【问题标题】:Add a style attribute to Html.BeginForm MVC/C#向 Html.BeginForm MVC/C# 添加样式属性
【发布时间】:2016-08-05 20:57:21
【问题描述】:
是否可以向 Html.BeginForm 添加样式属性?
类似:
@using (Html.BeginForm("Action","Controller", FormMethod.Post, new {@class="myClass"}, new {@style="margin-right:100px margin-top:50px"}))
{
}
【问题讨论】:
标签:
c#
html
css
model-view-controller
【解决方案1】:
试试
@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { style = "margin-right:100px; margin-top:50px", @class = "myClass" }))
{
}
【解决方案2】:
看这里:
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】:
//Try this format
@using (Html.BeginForm("Action", "Controller", null,FormMethod.Post, new { @style = "your styles ",@class = "your classname"}))
{
}
【解决方案4】:
@using (Html.BeginForm("Index", "Home", null, FormMethod.Post, new { style = "margin-right:100px;margin-top:50px;border:1px solid red;", @class = "thFormClass" }))
{
}
试试这个吧。