The following attribute is used to limit the 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:
[AjaxRequest] public ActionResult Login() { ... } [HttpPost, AjaxRequest] public ActionResult Login(LoginModel model, string returnUrl) { ... }
The following error occurs when creating an ajax message:
The current Login action request for the AgentController controller type is ambiguous between the following action methods: System.Web.Mvc.ActionResult Login () as NappWebsiteMvc.Controllers.AgentController System.Web.Mvc.ActionResult Login (NappWebsiteMvc.Models.Agent. LoginModel, System.String) by type NappWebsiteMvc.Controllers.AgentController
The HttpPost attribute seems to be ignored when using the optional attribute. If I remove the AjaxRequest attribute from the two methods, then the code will work.
What should be the correct implementation? Thanks!
source share