Is it possible to retrieve the posted form fields from within a parameterless HttpPost action method?
Non-HttpPost
public Actio开发者_高级运维nResult Edit(int id)
{
var model = repository.GetModel(id);
if(model==null) return View("NotFound");
return View(model);
}
HttpPost
[HttpPost]
public ActionResult Edit()
{
// First of all, we retrieve the id from the posted form field.
// But I don't know how to do.
var model = repository.GetModel(id);
if(model==null) return View("NotFound");
if(!TryUpdateModel(model))
return View(model);
repository.SaveChanges();
RedirectToAction("Status","Controller");
}
Is it possible to retrieve the posted form fields from within a parameterless HttpPost action method?
For posted form values:
var id = Request.Form["id"];
or:
[HttpPost]
public ActionResult Edit(FormCollection fc)
{
var id = fc["id"];
...
}
or for any request value (including form posted):
var id = Request["id"];
精彩评论