【问题标题】:How to add class to the form built with razor html helpers如何将类添加到使用 razor html 助手构建的表单中
【发布时间】:2012-12-08 11:23:23
【问题描述】:

我提到了this 的帖子, 但仍然无法正常工作。谁能告诉我我错在哪里?我的代码如下:

@using (Html.BeginForm("Login", "Account", 
                        FormMethod.Post, new { @class = "form" }))
{
    @Html.ValidationSummary(true, 
          "Log in was unsuccessful. Please correct the errors and try again.")

    <fieldset>
        <legend>Log in Form</legend>
        <ol>
            <li>
                @Html.LabelFor(m => m.UserName)
                @Html.TextBoxFor(m => m.UserName)
            </li>
            <li>
                @Html.LabelFor(m => m.Password)
                @Html.PasswordFor(m => m.Password)
            </li>
            <li>
                @Html.CheckBoxFor(m => m.RememberMe)
                @Html.LabelFor(m => m.RememberMe, new { @class = "checkbox" })
            </li>
        </ol>
        <input type="submit" value="Log in" />
    </fieldset>
    <p>
        @Html.ActionLink("Register", "Register") if you don't have an account.
    </p>

我想在这个表单中添加表单类。请帮助我..

【问题讨论】:

  • 您的css 中是否定义了form 类?浏览器源码是什么样子的?

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


【解决方案1】:

哦..我太傻了。我的 css 中有一个 id 而不是名为 form 的类。如果您在 css 文件中定义了表单类,则上述代码有效

【讨论】:

    猜你喜欢
    • 2012-08-30
    • 2016-01-26
    • 1970-01-01
    • 2012-11-26
    • 2017-11-01
    • 2019-11-06
    • 2022-12-18
    • 1970-01-01
    • 2013-07-12
    相关资源
    最近更新 更多