I have the following code in asp.net mvc where it is a textbox and I want to change it to a Dropdown list.
<div >
@Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
<div >
@Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
</div>
</div>
<div >
@Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
<div >
<select asp-for="name" asp-items="@Model.name" > </select>
@Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
</div>
</div>
CodePudding user response:
You must replace
@Html.EditorFor(...
for this
<label asp-for="SupervisorId"></label>
<select asp-for="SupervisorId" asp-items="@Model.Supervisors" >
</select>
<input name="SupervisorId" type="hidden" />
<span asp-validation-for="SupervisorId" ></span>