【问题标题】:Use 'class' (or other reserved keyword) as property on anonymous type使用“类”(或其他保留关键字)作为匿名类型的属性
【发布时间】:2010-09-22 05:11:18
【问题描述】:

好的,我找不到这个问题的答案:

<%: Html.ActionLink("Click Here", "Action", null, new {class="myClass"})%>

我想设置生成元素的 CSS 类属性。

显然,C# 不允许我使用“类”作为对象成员的名称。

我该怎么办?

【问题讨论】:

    标签: asp.net-mvc-2 html-helper anonymous-types


    【解决方案1】:

    您可以尝试使用 @ 转义课程吗?

    所以,请将您的代码修改为:

    <%: Html.ActionLink("Click Here", "Action", null, new {@class="myClass"})%>
    

    【讨论】:

      【解决方案2】:

      在 Class 中使用大写“C”也可以,从 this answer to a similar question 开始。属性名称转换为小写。

      <%: Html.ActionLink("Click Here", "Action", null, new { Class = "myClass" })%>
      

      【讨论】:

        猜你喜欢
        • 2017-09-25
        • 2017-07-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多