Q
Q
Quber2014-07-07 08:33:36
HTML
Quber, 2014-07-07 08:33:36

How to add CSS class to html form in ASP.NET MVC 4?

There is a standard login form:

@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))
{
    <!-- some -->
}

How to add a class to the form css tag?
Tried like this
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl, @class = "myclass" }))

But in the end it turns out
<form action="/Account/Login?ReturnUrl=%2F&amp;class=myclass" method="post">

Controller

public ActionResult Login(string returnUrl)
        {
            ViewBag.ReturnUrl = returnUrl;
            return View();
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Q
Quber, 2014-07-07
@Quber

@using (Html.BeginForm("ActionName", "ControllerName", 
            new { ReturnUrl = ViewBag.ReturnUrl }, 
            FormMethod.Post, new { @class="login-form" }))
{
  etc.
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question