如何将上边距应用于我的Html.BeginForm

时间:2011-07-25 12:00:18

标签: css asp.net-mvc html-helper

我有这段代码:

<div class="mdl_bdy_frm">
   @using (Html.BeginForm())
            {

            @Html.ValidationSummary(true, "Login was unsuccessful. Please correct the errors and try again.") 

            @Html.LabelFor(m => m.Login.UserName, new { @class = "adm" })
            @Html.TextBoxFor(m => m.Login.UserName, new { @class = "adm", size = 30 })
            @Html.ValidationMessageFor(m => m.Login.UserName)

            @Html.LabelFor(m => m.Login.Password, new { @class = "adm" })
            @Html.PasswordFor(m => m.Login.Password, new { @class = "adm", size = 30 })
            @Html.ValidationMessageFor(m => m.Login.Password)
            <br />
            @Html.CheckBoxFor(m => m.Login.RememberMe, new { @class = "adm" })
            @Html.LabelFor(m => m.Login.RememberMe, new { @class = "adm" })

            <p><input type="submit" value="Login" /></p>

        }
</div>

有没有办法让我的HTML.BeginForm以顶级边距的方式提供?如果可能的话,我想使用内置样式,因为它只是在一个地方使用。

3 个答案:

答案 0 :(得分:5)

您只需将padding添加到父div

即可

<div class="mdl_bdy_frm" style="padding-top:20px;">

答案 1 :(得分:3)

Html.BeginForm( ..., ..., ..., New With {.style = "margin-top:20px;"})

请参阅:How to add id HTML attribute in ASP.NET MVC w/ VB.NET

答案 2 :(得分:1)

@using (Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { style = "margin: 10px;" }))