其他人需要调整字段

时间:2014-08-29 12:07:39

标签: c# asp.net-mvc asp.net-mvc-4

是否可以在ASP.NET MVC中调整其他人的必填字段?

所以当它成真时

[Required(ErrorMessageResourceName = "ThisFieldIsRequired", ErrorMessageResourceType = typeof(Resource))]
[Display(Name = "IsPostAddressIsVisitingAddress", ResourceType = typeof(MyModelEntities.Properties.Resource))]
public bool IsPostAddressIsVisitingAddress { get; set; }

然后我们应该“开启”

[Required(ErrorMessageResourceName = "ThisFieldIsRequired", ErrorMessageResourceType = typeof(Resource))]

[Display(Name = "AddressLine1", ResourceType = typeof(MyModelEntities.Properties.Resource))]
public string PostAddressLine1 { get; set; }

谢谢!

1 个答案:

答案 0 :(得分:0)

感谢Andrei V.和Christophano

Conditional validation on model in MVC

http://foolproof.codeplex.com/

所以我刚刚添加了对该DLL的引用,它工作正常!

[RequiredIfTrue("IsPostAddressIsVisitingAddress",(ErrorMessageResourceName = "ThisFieldIsRequired", ErrorMessageResourceType = typeof(Resource))]