如何判断方法是否来自我的MVC操作过滤器中的get或post?

时间:2022-10-08 09:31:05

I have methods like this:

我有这样的方法:

    [HttpPost]
    public ActionResult Delete(BaseViewModel vm) {

    public ActionResult Delete(string ac) {
        try {

From within my action filter is there a way that I can check if the method is a post or get ?

从我的动作过滤器中有一种方法可以检查方法是帖子还是获取?

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {

??

??

1 个解决方案

#1


29  

The ActionExecutingContext has a HttpContext property. From there, you can obtain the Request property, which has a HttpMethod property, which tells you which method was used in this request.

ActionExecutingContext具有HttpContext属性。从那里,您可以获取Request属性,该属性具有HttpMethod属性,该属性告诉您在此请求中使用了哪种方法。

#1


29  

The ActionExecutingContext has a HttpContext property. From there, you can obtain the Request property, which has a HttpMethod property, which tells you which method was used in this request.

ActionExecutingContext具有HttpContext属性。从那里,您可以获取Request属性,该属性具有HttpMethod属性,该属性告诉您在此请求中使用了哪种方法。