I, have the partial view
@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">×</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" }) @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>
The partial view is call from the parent view
Here is the structure of the parent view
@{
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>
Controller method
public ActionResult PostUserAssignRole(UserRoleAssignmentViewModels model)
{
return RedirectToAction("usertest", "UserManagement", new { @id = TempData["MeetingTypeId"] });
}
I am getting the default value in the model. I can see the data is reflected to the UI. However on post the database not been pass to the controller method.
Model class
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; }
}
The modal data is binded to the UI however the post method doesnot send the data to the controller.