开发者

How can I check if a controller was called using post or get?

开发者 https://www.devze.com 2022-12-11 06:23 出处:网络
In ASP.Net MVC, how can I check in a controll开发者_如何学运维er method, if it was called using post or get?

In ASP.Net MVC, how can I check in a controll开发者_如何学运维er method, if it was called using post or get?

I am aware I can limit methods to being called only by post or by get - but how can I check for post/get in a method that allows both?


ControllerContext.HttpContext.Request.HttpMethod

or just

Request.HttpMethod 

in Controller


You can check the Request.HttpMethod property.


I use this combination for checking in view also

var method = Request.HttpMethod;

if (Request.HttpMethod == "POST") {
    var check = "";
}

if (Request.HttpMethod == "GET") {
    var check = "";
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号