【问题标题】:how to add angular tags to html attribute in razor如何在剃刀的html属性中添加角度标签
【发布时间】:2013-10-20 03:41:48
【问题描述】:
而不是这样做
<input type="checkbox" name="AltSchedule" ng-show="someVar" />
我希望能够做到这一点
@Html.CheckBoxFor(model => model.AltSchedule, new {ng-show="someVar" })
但我似乎无法找到关于使用带有角度标签的 html 助手完成谁的答案。有没有办法为 html 助手的 html 属性参数添加角度标签?
【问题讨论】:
标签:
asp.net-mvc
angularjs
razor
【解决方案1】:
htmlAttributes 参数中的下划线在控件呈现时会转换为连字符:
@Html.CheckBoxFor(model => model.AltSchedule, new {ng_show="someVar" })
【解决方案2】:
您可以使用带字典的重载:
@Html.CheckBoxFor(model => model.AltSchedule, new Dictionary<string, object>() { { "ng-show", "someVar" } })