Angular 2 MVC 5 Razor - How does one create an @Html.DropDownFor with angular attributes?

前端 未结 2 1329
再見小時候
再見小時候 2021-01-27 23:34

I wish to create something like this:


                        
    
提交评论

  • 2021-01-28 00:33

    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" }
        })
    
    0 讨论(0)
  • 提交回复
    热议问题