Michael
Michael

Reputation: 1022

how to add angular tags to html attribute in razor

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?

Upvotes: 20

Views: 8544

Answers (2)

Ryan Wright
Ryan Wright

Reputation: 3433

You can use the overload that takes a dictionary:

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

Upvotes: 4

ajbeaven
ajbeaven

Reputation: 9562

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

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

Upvotes: 39

Related Questions