asp.net mvc: how to detect when a page is called using ajax

后端 未结 6 1879
遥遥无期
遥遥无期 2021-02-12 20:26

how to detect when a page is called using ajax in asp.net mvc ?

6条回答
  •  佛祖请我去吃肉
    2021-02-12 21:05

    According to the Professional ASP.NET MVC 1.0 book, the MVC AJAX library will insert a form field called "X-Requested-With" with a value of "XMLHttpRequest".

    You can then use an extension method in System.Web.Mvc that means you can simply call Request.IsAjaxRequest() and get a simple true or false saying if this is an AJAX request.

提交回复
热议问题