Как определить, является ли представление для GET или POST в ASP .NET MVC?

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";
    }
}

PS: Для ядра точечной сети это:

Context.Request.Method == "POST"
22
задан FreeVice 18 October 2018 в 03:37
поделиться