asp.net-mvc-3

Why is IValidatableObject.Validate only called if property validation passes?

孤者浪人 提交于 2020-08-22 09:21:07
问题 In my model, it seems that Validate() is only called AFTER both properties pass validation. public class MyModel : IValidatableObject { [Required] public string Name { get; set;} [Required] public string Nicknames {get; set;} public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { if(Nicknames != null && Nicknames.Split(Environment.NewLine.ToCharArray()).Count() < 2) return yield result new ValidationResult("Enter at least two nicknames, new [] { "Nicknames" }); }

Html.CheckBoxFor not checked even though the model value is true

自古美人都是妖i 提交于 2020-08-04 02:29:14
问题 I've got a Razor partial view backed by a viewmodel containing, among other things, a bool called UseDuo. Let's say the UseDuo property is true, and I put the following code in my Razor: @Html.CheckBox("UseDuo", Model.UseDuo) @* Not checked *@ @Html.CheckBoxFor(m => m.UseDuo) @* Not checked *@ @Html.CheckBox("UseDuo2", Model.UseDuo) @* checked *@ @(Model.UseDuo ? "UseDuo=true" : "UseDuo=false") @* outputs UseDuo=true *@ The first two checkboxes come out not checked, but the third one is

Html.CheckBoxFor not checked even though the model value is true

偶尔善良 提交于 2020-08-04 02:27:24
问题 I've got a Razor partial view backed by a viewmodel containing, among other things, a bool called UseDuo. Let's say the UseDuo property is true, and I put the following code in my Razor: @Html.CheckBox("UseDuo", Model.UseDuo) @* Not checked *@ @Html.CheckBoxFor(m => m.UseDuo) @* Not checked *@ @Html.CheckBox("UseDuo2", Model.UseDuo) @* checked *@ @(Model.UseDuo ? "UseDuo=true" : "UseDuo=false") @* outputs UseDuo=true *@ The first two checkboxes come out not checked, but the third one is