MVC使用动作属性来映射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"; } }