【问题标题】: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" }))
      {
      
      }

      试试这个吧。

      【讨论】:

        猜你喜欢
        • 2011-02-20
        • 1970-01-01
        • 2010-09-18
        • 1970-01-01
        • 2011-12-07
        • 2013-07-22
        • 2014-12-21
        • 2014-04-18
        • 1970-01-01
        相关资源
        最近更新 更多