Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a style attribute to Html.BeginForm MVC/C#

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"}))
{
}
like image 227
Naughty Ninja Avatar asked Apr 14 '16 10:04

Naughty Ninja


4 Answers

try

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

}
like image 104
chsword Avatar answered Sep 21 '22 00:09

chsword


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

}
like image 22
Akshay Avatar answered Sep 20 '22 00:09

Akshay


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. :)

like image 26
Maciej S. Avatar answered Sep 22 '22 00:09

Maciej S.


@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.

like image 21
Abhishek Avatar answered Sep 18 '22 00:09

Abhishek