我有一个视图显示用户名及其所属的组。如果我切换用户组,我如何将机器人用户和新组发送到控制器?
查看:
<table>
<tr>
<td>user ID</td>
<td>user group</td>
<td>Actions</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.UserName</td>
<td>@Html.DropDownList("grup", new SelectList(ViewBag.GroupList, "ID", "UserGroupName"), item.UserGroupName)</td>
<td>@Html.ActionLink("Save","EditUserGroup", UserInGroup)</td>
</tr>
}
</table>
Viewbag.GroupList 是 {ID, GroupName} 的列表
控制器
public ActionResult EditUserGroup(UserInGroup userInGroup, string grup)
{
}
如何发送所选组的值和包含所有详细信息的用户?
编辑
我将模型更改为:
public class UserInGroupModel
{
public IList<UserInGroup> userInGroupList { get; set; }
public int GroupId { get; set; }
}
控制器
public ActionResult UserGroup()
{
IUserGroupService userGroupService = new UserGroupService();
ViewBag.GroupList = userGroupService.GetEntities();
var lista = userInGroupService.GetEntities();
UserInGroupModel userInGroupModel = new UserInGroupModel();
userInGroupModel.userInGroupList = lista;
return View(userInGroupModel);
}
看法:
@using (Html.BeginForm("EditUserGroup", "Admin"))
{
<table>
<tr>
<td>user ID</td>
<td>user group</td>
<td>Actions</td>
</tr>
@foreach (var item in Model.userInGroupList)
{
<tr>
<td>@item.UserName</td>
<td>@Html.DropDownListFor(model => model.GroupId, new SelectList(ViewBag.GroupList, "ID", "UserGroupName"))</td>
<td><input type="submit" value="Save"/></td>
</tr>
}
</table>
}
我仍然无法发送 UserInGroup 的值。我可以在控制器的 groupId 参数中获取 GroupId,但是没有传递 UserInModel 实体。你能帮助我吗 ?