【问题标题】: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" })
    

    【讨论】:

    • 谢谢,在您回答 4 年后,这对我有所帮助。
    【解决方案2】:

    您可以使用带字典的重载:

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

    【讨论】:

      猜你喜欢
      • 2022-01-18
      • 1970-01-01
      • 1970-01-01
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-26
      • 1970-01-01
      相关资源
      最近更新 更多