Problem in updating records in MVC
-
Hi there, I'm new to asp.net MVC like many of us. I'm trying to update data in the database through my asp.net MVC web application. Insert works fine but update. I'm using VS2008 SP1. Here is my code snippet, and actually I'm trying an example found in the net. :)
public ActionResult UpdateMyProduct()
{
Models.Product product = new Models.Product();
UpdateModel(product, Request.Form.AllKeys);
northwind.SubmitChanges();
return RedirectToAction("Detail", new { id = product.ProductID });
}When I debug my model doesn't get changed. Am I missing anything? I appreciate any help. Thanks in advance. kmuthuk
-
Hi there, I'm new to asp.net MVC like many of us. I'm trying to update data in the database through my asp.net MVC web application. Insert works fine but update. I'm using VS2008 SP1. Here is my code snippet, and actually I'm trying an example found in the net. :)
public ActionResult UpdateMyProduct()
{
Models.Product product = new Models.Product();
UpdateModel(product, Request.Form.AllKeys);
northwind.SubmitChanges();
return RedirectToAction("Detail", new { id = product.ProductID });
}When I debug my model doesn't get changed. Am I missing anything? I appreciate any help. Thanks in advance. kmuthuk
And where is this UpdateModel method? What does it do? How is your problem related to ASP.NET MVC?
only two letters away from being an asset
-
And where is this UpdateModel method? What does it do? How is your problem related to ASP.NET MVC?
only two letters away from being an asset
-
UpdateModel is a method of Controller class which updates the MVC Model with the object and its values. In this case, product and product values which are from Request.Form
You're having an issue with updating data and you have a method that updates data but you don't show it? See any problem here?
only two letters away from being an asset
-
You're having an issue with updating data and you have a method that updates data but you don't show it? See any problem here?
only two letters away from being an asset
-
[^] Actually, I was taking the code from the above article. UpdateFrom of Controller is part of framework, not my own method. This method has been replaced with UpdateModel in SP1. Thanks for your time. Happy Holidays -kmuthuk