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 and Node.js Stack. I develop my interests in Back-End development with ASP.NET Stack and DevOps development using Docker and Kubernetes, usually I using Linux for my development wokstation.