How to add "ng-model" to DropDownList?

I work in asp.net MVC4 with angularJs. I am trying to add "ng-model" to the dropdownlist. My DropDownListis is like this:

@Html.DropDownList("UnitConversionId", (IEnumerable<SelectListItem>)ViewBag.UnitConversionId, "No Unit Seleced", new { ng-model="newItem.UnitConversionId" }) 

I also tried this. But I get an error message:

 @Html.DropDownList("UnitConversionId", (IEnumerable<SelectListItem>)ViewBag.UnitConversionId, "No Unit Seleced", new { @ng-model="newItem.UnitConversionId" }) 

Can I add "ng-model" to DropDownList?

+6
source share
1 answer

You can get any attribute that contains a dash (just like all HTML5 data attributes) for rendering by changing the dash to an underscore in the definition:

 @Html.DropDownList("UnitConversionId", (IEnumerable<SelectListItem>)ViewBag.UnitConversionId, "No Unit Seleced", new { ng_model="newItem.UnitConversionId" }) 
+15
source

Source: https://habr.com/ru/post/952584/


All Articles