The following codes works. But the problem is when I click the edit link to edit a product the all the text boxes gets cleared but error message are working. This is happening because Strongly Typed View class is selected which contains error message with regex. That class is being used for Create operation as well. The thing is that I want to include the errors message if a text(es) is remained empty or invalid data is enter and user tries to save in those conditions. How do can this be achieved, if possible. I am using VS 2010, MVC C#, ADO.NET.
[HttpPost]
public ActionResult Edit(int id, FormCollection collection,
ProductCategory editCategory)
{
if (!ModelState.IsValid)
{
return View(editCategory);
}
var categoryToUpdate = db.ProductCategories.First(m =>
m.ProductCategoryID == id);
ViewData.Model = categoryToUpdate;
TryUpdateModel(categoryToUpdate, new string[] { },
collection.ToValueProvider());
db.AddToProductCategories(editCategory);
db.SaveChanges();
return View("/");
}