Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add angular tags to html attribute in razor

Tags:

rather than do this

<input type="checkbox" name="AltSchedule" ng-show="someVar" />

i want to be able to do this

@Html.CheckBoxFor(model => model.AltSchedule, new  {ng-show="someVar" })

but i can't seem to find an answer on who to accomplish using the html helpers with angular tags. Is there way to add angular tags to the html attributes parameter for an html helper?

like image 696
Michael Avatar asked Oct 11 '13 23:10

Michael


Video Answer


2 Answers

Underscores in the htmlAttributes parameter are converted to hyphens when the control is rendered:

@Html.CheckBoxFor(model => model.AltSchedule, new  {ng_show="someVar" })
like image 106
ajbeaven Avatar answered Oct 26 '22 08:10

ajbeaven


You can use the overload that takes a dictionary:

@Html.CheckBoxFor(model => model.AltSchedule, new Dictionary<string, object>() { { "ng-show", "someVar" } })
like image 37
Ryan Wright Avatar answered Oct 26 '22 08:10

Ryan Wright