ASP.NET MVC 2 - Reevaluate ModelState
我有一个由默认模型绑定器绑定的模型。
它基于
同一模型上的另一个属性有一个 setter 方法,该方法为该字段派生一个有效值并设置它。
但是原始的 ModelState 错误仍然存??在。
主要问题:我可以重新评估 ModelState 吗?
子问题:有没有更好的解决方案?
编辑
这是绑定模型的简化示例(针对子问题)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public class Booking { public List<Participant> Participants {get;set;} [Required] public string MainEmail {get;set;} private int _mainParticpantIndex; [Required] public int MainParticipantIndex { get { return _mainParticpantIndex; } set { _mainParticpantIndex= value; MainEmail = Particpants[value].Email } } } public class Participant { // not required for every participant. public string Email {get;set;} [Required] public string Name {get;set;} } |
我认为在这种情况下,您应该从
除非您希望能够覆盖主电子邮件,使其与主要参与者的不同。在这种情况下,您可能必须修改
的设置器
编辑
根据您的评论,您无法使用普通的