如何从MVC中的Web表单检索使用POST发送的值?

时间:2012-08-20 08:48:04

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

我正在使用MVC 3和C#我想知道如何检索使用POST发送的表单的值。

她的代码,但不起作用,eventTitle的值为null。知道我在这里做错了吗?谢谢你的时间。

  [HttpPostAttribute]
    public JsonResult AddEventCustom()
    {

            string eventTitle = Request.Form["EventTitle"];

            return Json(new { Message = "Success" }, JsonRequestBehavior.AllowGet);


        }

1 个答案:

答案 0 :(得分:2)

您可以在方法声明中简单地放置所需的变量。 MVC`将为您处理映射

[HttpPostAttribute]
public JsonResult AddEventCustom(string EventTitle) 
{ 
}