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



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

类似于:

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

尝试

@using (Html.BeginForm("Action", "Controller", FormMethod.Post, new { style = "margin-right:100px; margin-top:50px", @class = "myClass"  }))
{
}
//Try this format
@using (Html.BeginForm("Action", "Controller", null,FormMethod.Post, new { @style = "your styles ",@class = "your classname"}))
{
}

查看此处:

StackOverflow链接

另一个StackOverflow链接

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

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

希望这能有所帮助。:)

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

试试这个,它会起作用的。

最新更新