2

not finding anything like this on google... so I need some help.

When I have css formatting to make my form the way I want it, it will appear fine on my page, no problem there.

But...

When I put the actual form inside the following... it loses css formatting.

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()

    <FORM HTML HERE>
}

Anyone maybe have any idea what is wrong here?

Thanks in advance.

HTML :

  <form class="form-signin">
    <h2 class="form-signin-heading">Please sign in</h2>
    <input type="text" class="input-block-level" placeholder="Email address">
    <input type="password" class="input-block-level" placeholder="Password">
    <label class="checkbox">
      <input type="checkbox" value="remember-me"> Remember me
    </label>
    <button class="btn btn-large btn-primary" type="submit">Sign in</button>
  </form>

CSS :

.form-signin {
    max-width: 300px;
    padding: 19px 29px 29px;
    margin: 0 auto 20px;
    background-color: #fff;
    border: 1px solid #e5e5e5;
    -webkit-border-radius: 5px;
       -moz-border-radius: 5px;
            border-radius: 5px;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
       -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
            box-shadow: 0 1px 2px rgba(0,0,0,.05);
  }
  .form-signin .form-signin-heading,
  .form-signin .checkbox {
    margin-bottom: 10px;
  }
  .form-signin input[type="text"],
  .form-signin input[type="password"] {
    font-size: 16px;
    height: auto;
    margin-bottom: 15px;
    padding: 7px 9px;
  }
Slippy
  • 1,253
  • 5
  • 22
  • 43

1 Answers1

4

@using (Html.BeginForm()) renders as a <form> element.

So, since you are trying to nest a form within a form, the second <form> is ignored by the browser (see this post : https://stackoverflow.com/a/555970/971693).

You will have to pass your class when you create the form :

@Html.BeginForm({Action}, {controler}, FormMethod.Post, new { @class = "Class" })
Community
  • 1
  • 1
Yan Brunet
  • 4,727
  • 2
  • 25
  • 35