locked
<select class="form-control" asp-items="ViewBag.Market"></select> RRS feed

  • Question

  • User-1422983141 posted
    <label asp-for="Market" class="control-label"></label>
       <div class="input-group mb-3">
         <div class="input-group-prepend">
            <a asp-controller="Markets" class="btn btn-outline-secondary" id="button-addon1">Add</a>
          </div>
         <select class="form-control" asp-items="ViewBag.Market"></select>
         <span asp-validation-for="Market" class="text-danger"></span>
       </div>

    If I provide a option Value for the user to select a vlaue:

    <select class="form-control" asp-items="ViewBag.Market">
       <option>Select</option>
    </select>

    The validation will not trip as the form will accept "Select" as the user value;

    It would be great if the Data Annotations work with the select control but that doesn't  happen:

    [Display(Name = "Market", Description = "The Market Name.", Prompt = "Market Name", ShortName = "Market Name", Order = 1)]
    public string Market { get; set; }

    I would like a way to trip the validation on the view before going to the server if the selection is Select? 

    Saturday, September 28, 2019 2:53 AM

All replies

  • User-474980206 posted

    Set value to blank and only the text to “Select” of the option.

    Saturday, September 28, 2019 4:06 PM