部分视图不向控制器发送数据asp.net mvc

时间:2017-11-23 02:19:48

标签: c# asp.net asp.net-mvc

我有局部视图

@model BoardsXpress.Models.UserRoleAssignmentViewModels
@{
    var meetingTypeId = ViewBag.meetingTypeId;
    var meetingType = ViewBag.meetingType;}

<div class="modal-content">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="addUSerModalLabel">Assign Roles</h4>
    </div>
    @using (Html.BeginForm("PostUserAssignRole", "UserRole", FormMethod.Post))
            {
        @Html.TextBoxFor(m => m.MeetingTypeId , new { @type = "hidden", @Value= "@meetingTypeId" })
        <div class="modal-body">
            <div class="row form-group">

                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th scope="col">Users</th>
                            <th scope="col">Role</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.userListViewModel)
                        {
                            <tr>
                                <td>@Html.CheckBoxFor(m => m.userListViewModel.First(x => x.UserId == item.UserId).SelectedUser, new { @class = "form-check-input" })&nbsp;&nbsp;@item.FirstName</td>
                                <td>@Html.DropDownListFor(m => m.userListViewModel.First(n => n.UserId == item.UserId).SelectedRoleId, item.RolesConvert, "Select Roles", new { @class = "form-control" })</td>
                            </tr>
                        }
                    </tbody>
                </table>

            </div>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-secondary" id="close" data-dismiss="modal">Close</button>
            <button type="submit" class="btn btn-primary">Done</button>
        </div>
    }
</div>

部分视图是从父视图调用

以下是父视图的结构

    @{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_DashboardSidebar.cshtml";
    var meetingTypeId = ViewBag.meetingTypeId;
    var meetingType = ViewBag.meetingType;
}

<div id="rightdash-container">
<button data-toggle="modal" data-target="#addUserRolesModal" class="btn btn-primary pull-right addButton">Assign User</button>
<div class="modal fade" id="addUserRolesModal" tabindex="-1" role="dialog" aria-labelledby="addUSerModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        @Html.Action("UserRoleManagement", "UserRole", new { id = @meetingTypeId })

    </div>
</div>
</div>

控制器方法

public ActionResult PostUserAssignRole(UserRoleAssignmentViewModels model)
        {
            return RedirectToAction("usertest", "UserManagement", new { @id = TempData["MeetingTypeId"] });
        }

我在模型中获取默认值。我可以看到数据反映到UI。但是在发布时数据库没有传递给控制器​​方法。

模型类

    public class UserRoleAssignmentViewModels
    {

    public List<UserManagementViewModels> userListViewModel { get; set; }

        public Guid MeetingId { get; set; }
        public Guid MeetingTypeId { get; set; }
        public string MeetingType { get; set; }

    }

public class UserManagementViewModels
    {
        public string UserId { get; set; }
        public string Email { get; set; }
        public string PhoneNumber { get; set; }
        public string FirstName { get; set; }
        public string Organisation { get; set; }
        public string Designation { get; set; }
        public string Avatar { get; set; }
        public string Password { get; set; }
        public bool SelectedUser { get; set; }
        public string SelectTitle { get; set; }
}

模态数据绑定到UI但是post方法不会将数据发送到控制器。

0 个答案:

没有答案