Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 2 在ASP.NET MVC 2中使用ListBoxFor_Asp.net Mvc 2_Html Helper - Fatal编程技术网

Asp.net mvc 2 在ASP.NET MVC 2中使用ListBoxFor

Asp.net mvc 2 在ASP.NET MVC 2中使用ListBoxFor,asp.net-mvc-2,html-helper,Asp.net Mvc 2,Html Helper,我正在尝试更新特定组在我的应用程序中的角色。我在视图中使用的组模型附加了一个AllRoles IEnumerable,因此在我的视图中,我可以执行以下操作: <%: Html.ListBoxFor( model => model.aspnet_Roles, new MultiSelectList( Model.AllRoles, "RoleId", "RoleName" ), new { @class = "multiselect" } )%> [HttpPost] publ

我正在尝试更新特定组在我的应用程序中的角色。我在视图中使用的组模型附加了一个AllRoles IEnumerable,因此在我的视图中,我可以执行以下操作:

<%: Html.ListBoxFor( model => model.aspnet_Roles, new MultiSelectList( Model.AllRoles, "RoleId", "RoleName" ), new { @class = "multiselect" } )%>
[HttpPost]
public ActionResult Edit(SYSGroups updatedGroup) 
{
    // updatedGroup.Aspnet_Roles will contain an array of all the RoleIds
    // selected in the multiselect list.
    return View();
}

谢谢

所选ID将作为集合发送:

[HttpPost]
public ActionResult Edit(string[] aspnet_Roles) 
{
    // the aspnet_Roles array will contain the ids of the selected elements
    return View();
}
如果表单包含需要发布的其他元素,则可以更新模型:

public class SYSGroups
{
    public string[] Aspnet_Roles { get; set; }
    ... some other properties
}
让你的行动方法如下所示:

<%: Html.ListBoxFor( model => model.aspnet_Roles, new MultiSelectList( Model.AllRoles, "RoleId", "RoleName" ), new { @class = "multiselect" } )%>
[HttpPost]
public ActionResult Edit(SYSGroups updatedGroup) 
{
    // updatedGroup.Aspnet_Roles will contain an array of all the RoleIds
    // selected in the multiselect list.
    return View();
}

我可以避免在控制器功能中使用其他参数吗?我可以使用收到的aspnet_组来阅读收藏吗?public ActionResult Edit(SYSGroups updategroups){}是的,将
Aspnet_Roles
array属性添加到
SYSGroups
model类中,如我所示。您在
Html.ListBoxFor
中绑定到的属性需要是一个类似
Html.ListBoxFor(model=>model.aspnet_角色,
-
aspnet_角色
的数组。只需将该参数添加到控制器函数中就可以了,为我的model.Thx添加权重没有意义。