在 MVC DropDownListFor 中插入 AngularJs ng-model
Inserting AngularJs ng-model in MVC DropDownListFor
我已经按照 here 所述对下拉列表的值进行了硬编码,但我不知道如何实现 AngularJS 的 ng-model 在此特定设置中的 <select>
内,因此我可以插入 ng-model="categoryValue"
并获取下拉列表值。
<div class="editor-field" ng-model="categoryValue">
@Html.DropDownListFor(model => model.ticketType,
new SelectList(
new List<Object>{
new { value = "Hardware/Devices" , text = "Hardware/Devices" },
new { value = "Software/Drivers" , text = "Software/Drivers" },
new { value = "Access Tools" , text = "Access Tools"}
},
"value",
"text",
1))
@Html.ValidationMessageFor(model => model.ticketType)
</div>
上面的代码转换为
<select id="ticketType" name="ticketType">
<option value="Hardware/Devices">Hardware/Devices</option>
<option value="Software/Drivers">Software/Drivers</option>
<option value="Access Tools">Access Tools</option>
</select>
从 div 中删除 ng-model 并按如下方式应用于下拉列表希望它会起作用
<div class="editor-field">
@Html.DropDownListFor(model => model.ticketType,
new SelectList(
new List<Object>{
new { value = "Hardware/Devices" , text = "Hardware/Devices" },
new { value = "Software/Drivers" , text = "Software/Drivers" },
new { value = "Access Tools" , text = "Access Tools"}
},
"value",
"text",
1),new
{
ng_model = "categoryValue",
})
@Html.ValidationMessageFor(model => model.ticketType)
</div>
我已经按照 here 所述对下拉列表的值进行了硬编码,但我不知道如何实现 AngularJS 的 ng-model 在此特定设置中的 <select>
内,因此我可以插入 ng-model="categoryValue"
并获取下拉列表值。
<div class="editor-field" ng-model="categoryValue">
@Html.DropDownListFor(model => model.ticketType,
new SelectList(
new List<Object>{
new { value = "Hardware/Devices" , text = "Hardware/Devices" },
new { value = "Software/Drivers" , text = "Software/Drivers" },
new { value = "Access Tools" , text = "Access Tools"}
},
"value",
"text",
1))
@Html.ValidationMessageFor(model => model.ticketType)
</div>
上面的代码转换为
<select id="ticketType" name="ticketType">
<option value="Hardware/Devices">Hardware/Devices</option>
<option value="Software/Drivers">Software/Drivers</option>
<option value="Access Tools">Access Tools</option>
</select>
从 div 中删除 ng-model 并按如下方式应用于下拉列表希望它会起作用
<div class="editor-field">
@Html.DropDownListFor(model => model.ticketType,
new SelectList(
new List<Object>{
new { value = "Hardware/Devices" , text = "Hardware/Devices" },
new { value = "Software/Drivers" , text = "Software/Drivers" },
new { value = "Access Tools" , text = "Access Tools"}
},
"value",
"text",
1),new
{
ng_model = "categoryValue",
})
@Html.ValidationMessageFor(model => model.ticketType)
</div>