Ajax заявки в ASP.NET MVC

Наскоро ми се наложи да правя ASP.NET MVC приложение където ActionResult-те да се изпълняват само при Ajax заявки. Решението на проблема реших да го споделя и може да го намерите по долу.

public class AjaxOnlyAttribute : ActionMethodSelectorAttribute
{
    public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
    {
        return controllerContext.RequestContext.HttpContext.Request.IsAjaxRequest();
    }
}
Ivan Ivanov profile picture
Ivan Ivanov

I have many years experience of technical backhround as web developer with solid experience with .NET Platform, Node.js Stack and Python. I develop my interests in Back-End development with ASP.NET Stack and Docker for run it, usually I using Linux for my development wokstation.

Instagram