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;
  }
3
  • 1
    Post short-but complete HTML output showing your hand-coded HTML and the HTML generated by your example code. Commented Nov 12, 2012 at 0:48
  • It might help if you posted some of your CSS too. Commented Nov 12, 2012 at 1:07
  • Added, I gotta grab a train here, so it may be a while before I get to check back, but I really appreciate the help! Commented Nov 12, 2012 at 1:12

1 Answer 1

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" })
Sign up to request clarification or add additional context in comments.

3 Comments

Thankyou, it will be about 8 hours before I make it back home... I wll definitelgive this a try when I get home.
Thanks! Worked like a charm! :)
Sorry for the late marking of this, I hadn't realized it wasn't marked!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.