Questions tagged «model-validation»

11
MaxLength属性未生成客户端验证属性
我对ASP.NET MVC3客户端验证有一个奇怪的问题。我有以下课程: public class Instrument : BaseObject { public int Id { get; set; } [Required(ErrorMessage = "Name is required.")] [MaxLength(40, ErrorMessage = "Name cannot be longer than 40 characters.")] public string Name { get; set; } } 在我看来: <div class="editor-field"> @Html.EditorFor(model => model.Name) @Html.ValidationMessageFor(model => model.Name) </div> 这是我为此字段的文本框获取的生成的HTML: <input …

7
清单的ViewModel验证
我有以下视图模型定义 public class AccessRequestViewModel { public Request Request { get; private set; } public SelectList Buildings { get; private set; } public List<Person> Persons { get; private set; } } 因此,在我的应用程序中,必须至少有1个人才能进行访问请求。您可以使用哪种方法进行验证?我不希望这种验证在我的控制器中发生,这很容易做到。唯一选择是自定义验证属性吗? 编辑:当前正在执行此验证与FluentValidation(不错的库!) RuleFor(vm => vm.Persons) .Must((vm, person) => person.Count > 0) .WithMessage("At least one person is required");
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.