Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add "ng-model" in DropDownList?

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

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

I also tried this. But I am getting an error:

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

Is there any way to add an "ng-model" to DropDownList?

like image 898
raisul Avatar asked Aug 27 '13 10:08

raisul


1 Answers

You can get any kind of attribute that contains a dash (so also all kinds of HTML5 data attributes) to render by changing the dash to underscore in the definition:

@Html.DropDownList("UnitConversionId", (IEnumerable<SelectListItem>)ViewBag.UnitConversionId, "No Unit Seleced", new { ng_model="newItem.UnitConversionId" })
like image 86
Patryk Ćwiek Avatar answered Oct 09 '22 14:10

Patryk Ćwiek