6

Is it possible to add style attributes to a Html.BeginForm?

Something like:

@using (Html.BeginForm("Action","Controller", FormMethod.Post, new {@class="myClass"}, new {@style="margin-right:100px margin-top:50px"}))
{
}
threesixnine
  • 1,733
  • 7
  • 30
  • 56
  • Possible duplicate of [Adding CSS class to Html.BeginForm()](http://stackoverflow.com/questions/13984029/adding-css-class-to-html-beginform) – Smit Patel Apr 14 '16 at 11:01

4 Answers4

12

try

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

}
Smit Patel
  • 2,992
  • 1
  • 26
  • 44
chsword
  • 2,032
  • 17
  • 24
2
//Try this format
@using (Html.BeginForm("Action", "Controller", null,FormMethod.Post, new { @style = "your styles ",@class = "your classname"}))
{

}
Akshay
  • 71
  • 1
  • 7
1

Look here:

StackOverflow Link

Another StackOverflow Link

I'm not MVC expert, but according to attached links Your code should like this:

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

Hope this helps. :)

Community
  • 1
  • 1
Maciej S.
  • 752
  • 10
  • 22
1

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

}

Try this it will work.

Abhishek
  • 170
  • 8