0

我有一个简单的表单,有两个字段和一个可选字段,如果未选择复选框,则选择复选框时显示,如果未选择复选框 - 显示/隐藏由jQuery控制。问题是,当页面第一次加载时,表单像往常一样提交,但是一旦选中或取消选中复选框,提交按钮就不会提交表单,甚至更奇怪的是它什么也不做。

我有一个模型的强类型视图:

@model Metteem.ViewModels.SchedularAccount

我的简单脚本是:

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

表格的代码在哪里:

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

在我的操作中,我有一个 HttpPost 属性:

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

会出什么问题?

4

1 回答 1

1

感谢@avesse,添加类型作为提交解决了这个问题..

尝试<button type="submit" class="btn btn-primary">是否必须使用<button>元素。

于 2012-06-12T09:56:07.170 回答