How to determine if the view is for GET or POST in ASP.NET MVC?

后端 未结 3 764
梦如初夏
梦如初夏 2021-01-01 11:10

MVC use action attributes to map the same view for http get or post:

 [HttpGet] 
 public ActionResult Index()
 {
    ViewBag.Message = \"Message\";
    retur         


        
3条回答
  •  无人及你
    2021-01-01 12:02

    System.Web.HttpContext.Current.Request.HttpMethod stores current method. Or just Request.HttpMethod inside of view, but if you need to check this, there may be something wrong with your approach.

    Think about using Post-Redirect-Get pattern to form reposting.

提交回复
热议问题