2

我需要对视图模型属性执行两个单独的验证。显然,每个属性只能应用一次RemoteAttribute。这可能是一个愚蠢的问题,但有没有人知道解决这个问题的方法?有没有办法使用多个System.Web.Mvc.RemoteAttributes?获取“重复的RemoteAttribute属性”。

public class ForgotPasswordModel 
{ 
    // Getting compiler error "Duplicate RemoteAttribute attribute" 
    [Remote("CanFindEmail", "Account", ErrorMessageResourceName = "EmailNotFound", ErrorMessageResourceType = typeof(ValidationMessages))] 
    [Remote("IsAccountVerified", "Account", ErrorMessageResourceName = "AccountByEmailNotVerified", ErrorMessageResourceType = typeof(ValidationMessages))] 
    [Required(ErrorMessageResourceType = typeof(ValidationMessages), ErrorMessageResourceName = "PropertyRequired")] 
    [Display(ResourceType = typeof(Resx), Name = "PersonEmailAddress")] 
    public string Email { get; set; } 
} 

回答

2

有没有办法解决这个(因为RemoteAttribute不支持每个属性的多个声明)而无需重写MVC如何处理远程确认。一个Remote属性应指向执行所有远程验证的服务器上的一个方法。您应该在该服务器方法中汇总多个验证类型。每个属性不需要多个远程属性的原因是性能,因为每个额外的回调都会产生开销。

+0

这是不幸的,因为我需要能够有两种验证的具体错误方法... – gabe 2011-03-07 19:41:55

+0

您始终可以有一个方法调用两种验证方法。 – marcind 2011-03-07 20:06:00

+3

如何返回不同的错误信息? – 2014-12-07 15:14:39

相关问题