如何在使用razor html帮助器构建的表单中添加类

时间:2012-12-08 11:23:24

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

我提到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>

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

1 个答案:

答案 0 :(得分:2)

哦,我真是太傻了。我有一个id,而不是我的CSS中的类命名。如果您在css文件中定义了表单类

,则上述代码可以正常工作