Bootstrap下拉列表在ASP.NET MVC BeginForm中无法正常工作

时间:2017-07-14 08:31:43

标签: jquery asp.net asp.net-mvc twitter-bootstrap twitter-bootstrap-3

源代码:

@using (Html.BeginForm("PostEdit", "Users", FormMethod.Post, new { }))
{
    @Html.AntiForgeryToken()

    <!-- Begin .panel -->
    <section class="panel">

        <!-- Begin .panel-heading -->
        <header class="panel-heading">

            <h3 class="panel-title"><i class="fa fa-pencil"></i>Gebruiker wijzigen</h3>

            <!-- Begin .panel-actions -->
            <div class="panel-actions dropdown">
                <a href="javascript:;" class="dropdown-toggle" type="button" id="ddPanelActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                    <span class="fa fa-ellipsis-h"></span>
                </a>
                <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="ddPanelActions">
                    <li><a href="@Url.Action("Delete", "Users", new { Model.User.Id })">Verwijderen</a></li>
                </ul>
            </div><!-- End .panel-actions -->

        </header><!-- End .panel-heading -->

        // The form elements are here but I have removed them
        ....

    </section>
}

控制台错误:

jquery-3.1.1.js:4089 Uncaught TypeError: Cannot read property 'jQuery3110250078044400615432' of undefined
    at Data.get (jquery-3.1.1.js:4089)
    at Data.access (jquery-3.1.1.js:4107)
    at Function.data (jquery-3.1.1.js:4247)
    at HTMLAnchorElement.delegate (jquery.validate.js:407)
    at HTMLFormElement.dispatch (jquery-3.1.1.js:5201)
    at HTMLFormElement.elemData.handle (jquery-3.1.1.js:5009)
    at Object.trigger (jquery-3.1.1.js:8171)
    at Object.simulate (jquery-3.1.1.js:8230)
    at HTMLDocument.handler (jquery-3.1.1.js:8289)

当我将此代码放在BeginForm之外时,它就完美了。

更新

当我删除我的表单元素时,它的工作......

以下是我的表格:

      <div class="form-horizontal">

            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            @Html.HiddenFor(model => model.User.Id)

            <div class="form-group">
                @Html.LabelFor(model => model.User.Active, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    <div class="checkbox checkbox-default check-add-label">
                        @Html.EditorFor(model => model.User.Active)
                    </div>
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.User.Name, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.User.Name, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.User.Name, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.User.Username, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.User.Username, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.User.Username, "", new { @class = "text-danger" })
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.User.Password, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.User.Password, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.User.Password, "", new { @class = "text-danger" })
                </div>
            </div>
        </div>

0 个答案:

没有答案