【问题标题】:Is it possible to use CSS when coding with Razor HTML helpers使用 Razor HTML 助手进行编码时是否可以使用 CSS
【发布时间】:2016-03-10 19:13:23
【问题描述】:

我对 MVC 很陌生,只是通过示例学习,到目前为止我能够做到

@Html.RadioButton("settings", "UpdateEmail")

但是有没有像额外参数这样的方法,所以我也可以为它设置一些outline:nonealignment 属性?

在 Google 我找到了这个例子,但他也没有通过 CSS:http://www.tutorialsteacher.com/mvc/htmlhelper-radiobutton-radiobuttonfor

【问题讨论】:

    标签: c# css asp.net-mvc razor


    【解决方案1】:

    Razor 中的每个 HTMLHelper 都有 htmlProperty 参数,它接受一个对象并将在 html 中打印该对象的属性。

    所以,如果你想设置一个 CSS 类,你可以这样做:

    @Html.RadioButton("settings", "UpdateEmail", new {@class = "myCssClass"})
    

    这会变成这样:

    <input type="radio" name="settings" value="UpdateEmail" class="myCssClass">
    

    你可以通过这种方式设置任何属性:

    @Html.RadioButton("settings", "UpdateEmail", new {@class = "myCssClass", style="width: 100px", disabled="disabled"})
    

    注意:class 属性前的@ 是必需的,因为class 是保留字,所以使用@class 可以让你使用这个字。

    【讨论】:

      【解决方案2】:

      我相信你可以这样做:

      @Html.RadioButton("settings", "UpdateEmail", new { @class="inputclass" })

      @Html.RadioButton("settings", "UpdateEmail", new { style="outline: none;" })

      【讨论】:

        猜你喜欢
        • 2012-05-31
        • 2012-08-30
        • 2011-07-11
        • 1970-01-01
        • 2011-05-02
        • 2016-11-29
        • 2013-07-12
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多