ASP.NET MVC - 从部分视图提交表单

时间:2016-06-30 02:39:57

标签: asp.net asp.net-mvc asp.net-mvc-4 partial-views

在我的asp.net mvc 5应用程序中,每个CRUD操作都运行正常,没有任何部分视图。 Index.cshtml用于向所有员工显示他们被选中的课程。我需要添加一个下拉过滤器,以便我可以通过从下拉列表中选择课程来过滤员工。

我在我的Index.cshtml中添加了一个课程下拉列表,并在选择更改时,我启动了一个ajax调用以带来局部视图。在我的局部视图中,我在结果集上进行迭代,在每一行中我都有一个编辑按钮,可以打开该特定行的模态。我的问题是,当我将代码从主视图移动到局部视图时,编辑表单停止工作。控制台上没有错误,但表单无法提交。

这是我的局部视图中的代码:

<table class="display" id="dtAttendees">
        <thead>
        <tr>
            <th>ID</th>
            <th>Attendee Name</th>
            <th>Course</th>
            <th>Actions</th>
        </tr>
        </thead>
        <tbody>
        @foreach (AttendeeUserTbl attendee in Model)
        {
            <tr>
                <td>@attendee.AttendeeId</td>
                <td>@attendee.AttendeeName</td>
                <td>@attendee.CourseName</td>
                <td>
                    <a href="#" class="btn btn-icon-only green-original" title="Edit" data-toggle="modal" data-target="#attendeeIdss@(attendee.AttendeeId)"><i class="fa fa-edit"></i></a>
                </td>
            </tr>

            <!--Edit Modal start-->
            <div id="attendeeIdss@(attendee.AttendeeId)" class="modal fade" role="dialog">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title">Attendee Management</h4>
                        </div>

                        @using (Html.BeginForm("SaveAttendee", "User", FormMethod.Post, new {@class="form-horizontal"}))
                        {
                            @Html.HiddenFor(p => attendee.AttendeeId)
                            <div class="row">
                                <div class="form-group col-md-6">
                                    <label class="control-label">Attendee Name</label>
                                    @Html.TextBoxFor(p => attendee.AttendeeName, new { @class = "form-control", id = "txtEditAttendeeName" + attendee.AttendeeId, placeholder = "enter attendee name..", data_validation = "required" })
                                </div>                                        
                            </div>
                            <div class="modal-footer">
                                <button type="submit" class="btn btn-success">Update Attendee</button>
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                            </div>
                        }
                    </div>
                </div>
            </div>
        }
        </tbody>
    </table>

当我在任何行中单击编辑但它没有将表单提交到/ User / SaveAttendee时,它会生成正确的模态。当我将它移动到我的主父视图时,相同的代码可以工作。

由于任何地方都没有错误并且它与主视图一起使用,我无法理解该行为。你可以指导我或告诉我在我的部分观点中我做错了什么吗?真的很值得。

谢谢

0 个答案:

没有答案
相关问题