ejaz mirza

ejaz mirza

  • NA
  • 471
  • 47.5k

insert and edit the data using treeview control in mvc

Jun 29 2018 7:42 AM
  1. public ActionResult chartofaccountscreate()  
  2.        {  
  3.            // ViewBag.accountname = new SelectList(mse.chartofaccounts, "AccountName", "AccountName");  
  4.            treeviewlist();  
  5.            return View();  
  6.        }  
  7.   
  8.        [HttpPost]  
  9.        public ActionResult chartofaccountspost(FormCollection col)  
  10.        {  
  11.            chartofaccount coa = new chartofaccount();  
  12.            UpdateModel(coa);  
  13.            treeviewlist();  
  14.            if (ModelState.IsValid)  
  15.            {  
  16.                mse.chartofaccounts.Add(coa);  
  17.                mse.SaveChanges();  
  18.            }  
  19.            return View("chartofaccountscreate");  
  20.        }  
  21.   
  22.        public void treeviewlist()  
  23.        {  
  24.            List<chartofaccount> all = new List<chartofaccount>();  
  25.            using (mastersEntities dc = new mastersEntities())  
  26.            {  
  27.                all = dc.chartofaccounts.OrderBy(a => a.AccountName).ToList();  
  28.            }  
  29.            ViewBag.accountname = all;  
  30.        }  
  31.        public ActionResult chartofaccountedit(String name)  
  32.        {  
  33.            treeviewlist();  
  34.            chartofaccount data=null;  
  35.            if (name == null) {  
  36.   
  37.                
  38.                return View("chartofaccountscreate");  
  39.            }  
  40.            else  
  41.            {  
  42.                  
  43.               data = mse.chartofaccounts.SingleOrDefault(x => x.AccountName == name);  
  44.                int aid=data.ID;  
  45.   
  46.                return View("chartofaccountscreate", data);  
  47.            }  
  48.   
  49.        }  
  1.           <input type="input" class="form-control" id="input-select-node" placeholder="Identify node..." value="Parent 1" style="margin-left:50px">  
  2. <script>  
  3.    $(function () {  
  4.             $("#edit").click("change", (function () {  
  5.                 search = $('#input-select-node').val();  
  6.                  
  7.                 $.ajax({  
  8.                     type: 'GET',  
  9.                     url: '/chartofaccounts/chartofaccountedit{id}',  
  10.                     contentType: "application/json; charset=utf-8",  
  11.                     data: { name: search},  
  12.                     cache: false,  
  13.                     success: function (data) {  
  14.   
  15.                         alert(success);  
  16.                     },  
  17.                     error: function (XMLHttpRequest, textStatus, errorThrown) {  
  18.                         alert("data not found" + textStatus + errorThrown);  
  19.                     }  
  20.                 });  
  21.             }));  
  22.         });  
  23. </script>  
am returning the selected node data to the view when i return the data controller to view it shows the error that data not foud i have the data