开发者

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"];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜