0

I have a simple form with two fields and an optional field which is showed when a checkbox is selected and hidden if the checkbox is not selected - the show/hide is controlled by jQuery. The problem is that when the page is loaded first time the form is submitted as usual but once the checkbox is checked or unchecked the submit button does not submit the form or even more weird it does nothing.

I have a strongly-typed view with model:

@model Metteem.ViewModels.SchedularAccount

And my simple script is:

<script type="text/javascript">
$(document).ready(function () {
    $("#showhide").click(function () {
        $("#alternatingInput").toggle('fast');
    });
});
</script>

Where the code of the form is:

@using (Html.BeginForm(null, null, FormMethod.Post, new { Class = "well form-horizontal" }))
{
    <fieldset>
        <div class="control-group">
            <label class="control-label">Meeting ID</label>
            <div class="controls">
                @Html.TextBoxFor(model => model.MeetingId, new { Class = "input-xlarge" })
                @Html.ValidationMessageFor(model => model.MeetingId, null, new { Class = "help-inline" })
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Password</label>
            <div class="controls">
                @Html.PasswordFor(model => model.Password, new { Class = "input-xlarge" })
                @Html.ValidationMessageFor(model => model.Password, null, new { Class = "help-inline" })
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Login as Host?</label>
            <div class="controls">
                @Html.CheckBoxFor(model => model.IsHost, new { Class = "input-xlarge", id = "showhide" })
            </div>
        </div>
        <div class="control-group" id="alternatingInput" style="display: block; ">
            <label class="control-label">Participant ID</label>
            <div class="controls">
                @Html.TextBoxFor(model => model.UserId, new { Class = "input-xlarge", Value = "0" })
            </div>
        </div>

    </fieldset>
    <div class="form-actions">
        @Html.ActionLink("Cancel", "Index", "Home", null, new { Class = "btn" })
        <button class="btn btn-primary">Login</button>
    </div>
}

In my action I have an HttpPost attribute:

[HttpPost]
public ActionResult HostParticipantLogin(SchedularAccount account)
{
   //Rest of my code
}

What can be go wrong?

6
  • Have you enabled client side validation? Commented Jun 10, 2012 at 20:09
  • shouldn't the button be a submit button ? i.e <input type=submit class="btn btn-primary" Value="Login" /> ? Commented Jun 10, 2012 at 22:09
  • @gdoron Firebug doesn't give any clues unfortunately, the only change is that display option is block when the checkbox is unchecked and none when it is checked: <div class="control-group" id="alternatingInput" style="display: block; "></div> Commented Jun 10, 2012 at 22:23
  • @DarinDimitrov yes, the client side validation is enabled. Though it doesn't matter because it is not because of the empty hidden textbox, if it was filled the sitution doesn't change. Commented Jun 10, 2012 at 22:29
  • 1
    Try <button type="submit" class="btn btn-primary"> if you have to use a <button> element. Commented Jun 11, 2012 at 19:35

1 Answer 1

1

Thanks to @avesse, adding type as submit solves the problem..

Try <button type="submit" class="btn btn-primary"> if you have to use a <button> element.

Sign up to request clarification or add additional context in comments.

Comments

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.