开发者

ActionMethodSelectorAttribute getting lost between methods

开发者 https://www.devze.com 2023-03-29 20:18 出处:网络
I have 2 Actions using a custom made IsWWWAttribute attribute that inherits from ActionMethodSelectorAttribute, I am getting the following error when trying to call the post method:

I have 2 Actions using a custom made IsWWWAttribute attribute that inherits from ActionMethodSelectorAttribute, I am getting the following error when trying to call the post method:

System.Reflection.AmbiguousMatchException The current request for action 'forgotpassword' on controller type 'AccountsController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult ForgotPassword() on type .Controllers.AccountsController System.Web.Mvc.ActionResult ForgotPassword(.Models.ForgotPasswordModel) on type .Controllers.AccountsController

    [IsWWW]
    public ActionResult ForgotPassword()
    {
        // SOME CODE
    }
    [HttpPost]
    [IsWWW]
    p开发者_如何学Cublic ActionResult ForgotPassword(ForgotPasswordModel model)
    {
        // SOME CODE
    }

The custom attribute:

    public class IsWWWAttribute : ActionMethodSelectorAttribute
{
    public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo)
    {
        return Configuration.Subdomain.SubDomainID == 0;
    }
}

If I remove the [IsWWW] then calling the post action works fine!

What am I missing here!


Maybe check first ActionMethodSelectorAttribute base.IsValidForRequest() method result ? And then run your logic...


ActionMethodSelectorBase.RunSelectionFilters will return all the actions that match and both methods are valid on post. Add a [HttpGet] on the top method to invalid it on the PostBack

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号