The following attribute is used to restrict use of an action to an ajax request:
public class AjaxRequestAttribute : ActionMethodSelectorAttribute
{
public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
{
return controllerContext.HttpContext.Request.IsAjaxRequest();
}
}
I have the following controller action methods defined:
[AjaxRequest]
public ActionResult Login()
{
...
}
[HttpPost, AjaxRequest]
public ActionResult Login(LoginModel model, string returnUrl)
{
...
}
The following error occurs when the ajax post is made:
The current request for action 'Login' on controller type 'AgentController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Login() on type NappWebsiteMvc.Controllers.AgentController System.Web.Mvc.ActionResult Login(NappWebsiteMvc.Models.Agent.LoginModel, System.String) on type NappWebsiteMvc.Controllers.AgentController
It seems that the HttpPost attribute is ignored when using the additional attribute. If I remove the AjaxRequest attribute from the two methods, then the code works.
What should be the correct implementation? Thanks!