When implementing Edit action, I add two methods for Get and Post: Edit(string id)
Ideally, they need have same signature. But of course this is not compilable. So I add a dummy parameter to 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 Edit action?