是否可以从无参数的HttpPost操作方法中检索已发布的表单字段?

时间:2011-02-17 06:57:36

标签: asp.net-mvc asp.net-mvc-3

非HttpPost

public ActionResult 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");
}

是否可以从无参数的HttpPost操作方法中检索已发布的表单字段?

1 个答案:

答案 0 :(得分:1)

对于已过帐的表单值:

var id = Request.Form["id"];

或:

[HttpPost]
public ActionResult Edit(FormCollection fc)
{
    var id = fc["id"];
    ...
}

或任何请求值(包括已发布的表单):

var id = Request["id"];
相关问题