[英]Trying to create a dropdown list and textbox, setting list item as data and text box as value - asp.net mvc 4
[英]How to change textbox to dropdown list in asp.net mvc?
我在 asp.net mvc 中有以下代码,它是一个文本框,我想将其更改为下拉列表。
<div class="form-group">
@Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<select asp-for="name" asp-items="@Model.name" class="form-control"> </select>
@Html.ValidationMessageFor(model => model.name, "", new { @class = "text-danger" })
</div>
</div>
你必须更换
@Html.EditorFor(...
为了这
<label asp-for="SupervisorId"></label>
<select asp-for="SupervisorId" asp-items="@Model.Supervisors" class="form-control">
</select>
<input name="SupervisorId" type="hidden" />
<span asp-validation-for="SupervisorId" class="text-danger"></span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.