Tuesday, January 22, 2019

If the control, its label, and its validation control are all wrapped together in a div with display: none; on it in an MVC view...

Well, the validation won't validate. This can be a blessing in disguise. Unhide the div when you are ready. An example of what I'm talking about is...

<div style="display: none;" id="unhideMe">
   <label asp-for="@Model.Yin"></label>
   <select asp-for="@Model.Yin" asp-items="@Model.Yang" required>
      <option value="">-- Please Select --</option>
   </select>
   <span asp-validation-for="@Model.Yin"></span>
</div>

 
 

The required keyword is legit HTML. I'm not sure how it does its magic. This has some more on it and it basically says that the first setting in the dropdown list has to be an empty value.

No comments:

Post a Comment