将样式属性添加到Html.BeginForm MVC / C#

时间:2016-04-14 10:48:14

标签: c# html css model-view-controller

是否可以将样式属性添加到Html.BeginForm?

类似的东西:

@using (Html.BeginForm("Action","Controller", FormMethod.Post, new {@class="myClass"}, new {@style="margin-right:100px margin-top:50px"}))
{
}

4 个答案:

答案 0 :(得分:3)

@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { style = "margin-right:100px; margin-top:50px", @class = "myClass"  }))
{

}

答案 1 :(得分:2)

//Try this format
@using (Html.BeginForm("Action", "Controller", null,FormMethod.Post, new { @style = "your styles ",@class = "your classname"}))
{

}

答案 2 :(得分:1)

看这里:

StackOverflow Link

Another StackOverflow Link

我不是MVC专家,但根据附件链接您的代码应该是这样的:

@using (Html.BeginForm("Action","Controller", FormMethod.Post, new {@class="myClass"}, new {style="margin-right:100px margin-top:50px"}))
{
}

希望这会有所帮助。 :)

答案 3 :(得分:1)



@using (Html.BeginForm("Index", "Home", null, FormMethod.Post, new { style = "margin-right:100px;margin-top:50px;border:1px solid red;", @class = "thFormClass" }))
{

}




试试这个它会起作用。