suman goud

suman goud

  • NA
  • 176
  • 53.8k

how get id from html helper to controller in MVC 4

Jul 18 2016 7:53 AM

html helper

<a href="#@i.EmpID,new{[email protected]}" onclick="">@i.Name</a>

controller

public ActionResult addMaster(MasterNode master,int? id) {

 try { if (ModelState.IsValid) 
{                     using ( TestDemoEntities db = new TestDemoEntities()) 
{ var newMaster = db.MasterNodes.Create();                   
      newMaster.Name = master.Name;                      
   newMaster.HasEmployees =master.HasEmployees;        
                 newMaster.ReportsTo = id.Value;          
               newMaster.Description = master.Description;   
                      db.MasterNodes.Add(newMaster);         
                db.SaveChanges(); 
return RedirectToAction("Index", "Treeview"); 
}
 } 
else {
 ModelState.AddModelError("","Data is not correct"); 
} 
} 
catch(Exception e) 
{ 
throw;
 } 
return View();

i want to set EmpID as value for the reportsTo


Answers (1)