ejaz mirza

ejaz mirza

  • NA
  • 471
  • 47.4k

passing the data to the view from different controller

Jul 1 2018 11:38 PM
  1. private mastersEntities mse = new mastersEntities();  
  2.        
  3.       public ActionResult chartofaccountscreate()  
  4.       {  
  5.           // ViewBag.accountname = new SelectList(mse.chartofaccounts, "AccountName", "AccountName");  
  6.           treeviewlist();  
  7.           return View();  
  8.       }  
  9.   
  10.       [HttpPost]  
  11.       public ActionResult chartofaccountspost(FormCollection col)  
  12.       {  
  13.           chartofaccount coa = new chartofaccount();  
  14.           UpdateModel(coa);  
  15.           treeviewlist();  
  16.           if (ModelState.IsValid)  
  17.           {  
  18.               mse.chartofaccounts.Add(coa);  
  19.               mse.SaveChanges();  
  20.           }  
  21.           return View("chartofaccountscreate");  
  22.       }  
  23.   
  24.       public void treeviewlist()  
  25.       {  
  26.           List all = new List();  
  27.           using (mastersEntities dc = new mastersEntities())  
  28.           {  
  29.               all = dc.chartofaccounts.OrderBy(a => a.AccountName).ToList();  
  30.           }  
  31.           ViewBag.accountname = all;  
  32.       }  
  33.       
  34.       public ActionResult chartofaccountedit(String name)  
  35.       {  
  36.           treeviewlist();  
  37.           chartofaccount data=new chartofaccount();  
  38.            
  39.           if (name == null)  
  40.           {  
  41.   
  42.   
  43.               return View("chartofaccountscreate");  
  44.           }  
  45.           else  
  46.           {  
  47.   
  48.               data = mse.chartofaccounts.SingleOrDefault(x => x.AccountName == name);  
  49.                
  50.               if (data == null)  
  51.               {  
  52.                   return View("chartofaccountscreate");  
  53.               }  
  54.               else  
  55.               {  
  56.                 
  57.                   return View("chartofaccountscreate",data);  
  58.           }  
  59.   
  60.           }  
  61.   
  62.       }  

please see the image for better understanding in that i want create edit delete in the same view when i select the node and click on edit passing the data to the view the data is not filling in the textboxes the data is comming and unique data only but its not filling the form please help me out from the problem


Answers (2)