Detecting IsAjaxRequest() with ASP.NET MVC and JQuery Form Plugin / File Upload

后端 未结 4 1356
广开言路
广开言路 2020-12-06 11:47

I\'m using the JQuery Form plugin to do a file upload on an ASP.NET MVC application. I\'ve learned that since an iframe is used for file uploads (rather than XMLHttpRequest

4条回答
  •  借酒劲吻你
    2020-12-06 12:39

    As of ASP.NET MVC 2 (and onwards) there is an extension method on the Request.

    if (Request.IsAjaxRequest())
    {
         // was an ajax request
    }
    

    Using a jQuery method such as .load() on a controller method will result in Request.IsAjaxRequest() returning true.

提交回复
热议问题