DataAnnotations 验证和自定义模型绑定器
我有一个接受以下模型的操作方法 - LanguagesViewModel:
public class LanguagesViewModel : ViewModelBase
{
IEnumerable<LanguageItem> Languages { get; set; }
}
public class LanguageItem
{
[Required]
public int LanguageId { get; set; }
[Required]
public int SpeakingSkillId { get; set; }
[Required]
public int WritingSkillId { get; set; }
[Required]
public int UnderstandingSkillId { get; set; }
}
我还有一个自定义模型绑定器,用于将 POST 数据绑定到 IEnumerable
。
问题是如何让 DataAnnotations 验证发挥作用?
I have an action method that accepts the following model - LanguagesViewModel:
public class LanguagesViewModel : ViewModelBase
{
IEnumerable<LanguageItem> Languages { get; set; }
}
public class LanguageItem
{
[Required]
public int LanguageId { get; set; }
[Required]
public int SpeakingSkillId { get; set; }
[Required]
public int WritingSkillId { get; set; }
[Required]
public int UnderstandingSkillId { get; set; }
}
I also have a custom model binder to bind the POST data to the IEnumerable<LanguageItem>
.
The question is how do I get DataAnnotations validation to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道答案很晚了,它是针对 MVC3 的。将以下内容添加到模型绑定器 BindModel 方法的末尾
Very late answer I know, and it's for MVC3. Add the following to the end of your model binder BindModel method