2011-08-23 55 views
0

之间我必须使用定制IsWWWAttribute属性,从ActionMethodSelectorAttribute继承2个操作,我正在试图调用POST方法时出现以下错误:ActionMethodSelectorAttribute迷路方法

System.Reflection.AmbiguousMatchException 的当前请求在控制器类型'AccountsController'上操作'forgotpassword'在以下操作方法之间不明确:System.Web.Mvc.ActionResult ForgotPassword()对类型.Controllers.AccountsController System.Web.Mvc.ActionResult忘记密码(.Models.ForgotPasswordModel)on类型.Controllers.AccountsController

[IsWWW] 
    public ActionResult ForgotPassword() 
    { 
     // SOME CODE 
    } 
    [HttpPost] 
    [IsWWW] 
    public ActionResult ForgotPassword(ForgotPasswordModel model) 
    { 
     // SOME CODE 
    } 

自定义属性:

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

如果我删除[IsWWW]然后调用后行动工作正常!

我在这里错过了什么!

回答

0

也许先检查ActionMethodSelectorAttribute base.IsValidForRequest()方法的结果?然后运行你的逻辑...

0

ActionMethodSelectorBase.RunSelectionFilters将返回匹配的所有动作,并且这两个方法在发布后都是有效的。在顶部方法上添加一个[HttpGet],以使其在PostBack上无效