MVC使用action屬性映射爲HTTP GET或POST了同樣的觀點:如何確定視圖是用於ASP.NET MVC中的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";
}
}