Angular 2 MVC 5 Razor-如何创建具有角度属性的@ Html.DropDownFor? [英] Angular 2 MVC 5 Razor - How does one create an @Html.DropDownFor with angular attributes?
本文介绍了Angular 2 MVC 5 Razor-如何创建具有角度属性的@ Html.DropDownFor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建类似这样的东西:
I wish to create something like this:
<select class="form-control" ([ngModel])="selectedWorkout" (ngModelChange)="updateWorkout($event)" #selectList="ngModel">
<option value="44">Pick me!</option>
</select>
在剃须刀中使用Html.DropDownFor.我怎样才能做到这一点?具体来说,如何添加([ngModel]),(ngModelChange)和#selectList?
Using Html.DropDownFor in razor. How can I do that? Specifically, how do I add in ([ngModel]), (ngModelChange), and #selectList?
我的下拉菜单如下:
@Html.DropDownListFor(m => m.itemId, Model.itemList, new { @class = "form-control" })
推荐答案
我最终发现了这一点.重载之一使用字典的html属性,而不是对象.我用这本字典添加必需的元素.
I ended up finding this out. One of the overloads uses a dictionary for the html attributes rather than an object. I use this dictionary to add the required elements.
@Html.DropDownListFor(m => m.itemId, Model.itemList, new Dictionary<string, object>()
{
{ "class", "form-control" },
{ "required", String.Empty },
{ "maxlength", "4" },
{ "minlength", "2" },
{ "[(ngModel)]", "dataForm.itemId" }
})
这篇关于Angular 2 MVC 5 Razor-如何创建具有角度属性的@ Html.DropDownFor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文