When implementing the "Edit" action, I add two methods for Get and Post: Change (string identifier)
Ideally, they should have the same signature. But of course, this is not possible. Therefore, I am adding a dummy parameter to the HttpPost method (form in my case):
[HttpGet]
public ActionResult Edit(string id)
{
var user = Entities.Users.SingleOrDefault(s => s.UserID == id);
return View(user);
}
[HttpPost]
public ActionResult Edit(string id, FormCollection form)
{
var user = Entities.Users.SingleOrDefault(s => s.UserID == id);
if (TryUpdateModel<User>(user, new[] { "Email", "FullName" }))
{
Entities.SaveChanges();
RedirectToAction("Index");
}
return View(user);
}
Any better / cleaner way to implement the edit action?
source
share