【发布时间】:2011-02-14 16:41:49
【问题描述】:
MVC 使用 action 属性为 http get 或 post 映射相同的视图:
[HttpGet]
public ActionResult Index()
{
ViewBag.Message = "Message";
return View();
}
[HttpPost]
public ActionResult Index(decimal a, decimal b, string operation)
{
ViewBag.Message = "Calculation Result:";
ViewBag.Result = Calculation.Execute(a, b, operation);
return View();
}
在 MVC 视图中,如何确定该视图是用于 http get 还是 http post?
在视图中是IsPost
@{
var Message="";
if(IsPost)
{
Message ="This is from the postback";
}
else
{
Message="This is without postback";
}
}
PS:对于dot net core是:
Context.Request.Method == "POST"
【问题讨论】:
标签: asp.net-mvc