asp.net-mvc – 如何确定视图是否为ASP.NET MVC中的GET或POST?
发布时间:2020-12-16 00:40:15 所属栏目:asp.Net 来源:网络整理
导读: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 = "Calculati
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"; } } 解决方法
System.Web.HttpContext.Current.Request.HttpMethod存储当前方法。或者只是Request.HttpMethod内部的视图,但如果你需要检查这一点,你的方法可能会有问题。
考虑使用Post-Redirect-Get模式来形成转发。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- asp.net – 在Publish上自动压缩html和css?
- ASP.NET 实现Replace忽略大小写替换
- asp.net – .net网络应用程序中的异常处理
- asp.net-mvc – 从ASP.NET MVC中采用“aspnet_ …
- 在ASP.NET MVC 2中实现DropDownList的最佳方式?
- asp.net – 是否有一种简单的方法可以强制用户使
- asp.net – Visual Studio 2015 RC中的界面上的错
- asp.net-mvc – 我必须做什么才能从MVC控制器重定
- Asp.NET DropDownList在PostBack之后重置Selecte
- 在没有母版页控件的情况下在asp.net中打印页面
热点阅读