Welcome to Another tutorial on ASP.net MVC Database CRUD's Update tutorial.
Lets start without any delay.
At first Create a UC user Context in top of class.
private userContext UC = new userContext();
Now make an ActionResult method as follows:
[HttpGet]
public ActionResult update(string username) //passing username to change
{
user usr = UC.users.SingleOrDefault(u => u.username == username); //bringing a row to //change
usr.username = "John"; //changing old username to 'john'
UC.SubmitChanges(); //confirming change...
return RedirectToAction("users", "Home"); //After updating user return view of users list
}
Above piece of code will easily allow you to update the user. By knowing these basics you can make your own advanced form of code with some HTML form type of work in HttpPost also.GoodLuck.
If you want to learn more on User context and how that UC is working then you can watch this video too for more clear understanding.
Lets start without any delay.
At first Create a UC user Context in top of class.
private userContext UC = new userContext();
Now make an ActionResult method as follows:
[HttpGet]
public ActionResult update(string username) //passing username to change
{
user usr = UC.users.SingleOrDefault(u => u.username == username); //bringing a row to //change
usr.username = "John"; //changing old username to 'john'
UC.SubmitChanges(); //confirming change...
return RedirectToAction("users", "Home"); //After updating user return view of users list
}
Above piece of code will easily allow you to update the user. By knowing these basics you can make your own advanced form of code with some HTML form type of work in HttpPost also.GoodLuck.
If you want to learn more on User context and how that UC is working then you can watch this video too for more clear understanding.