Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.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
C# Asp.net MVC Nhibernate未在列表框中收集选定项_C#_Asp.net Mvc 3_Nhibernate_Razor - Fatal编程技术网

C# Asp.net MVC Nhibernate未在列表框中收集选定项

C# Asp.net MVC Nhibernate未在列表框中收集选定项,c#,asp.net-mvc-3,nhibernate,razor,C#,Asp.net Mvc 3,Nhibernate,Razor,当用户在角色中选择项目并提交时,模型不会填充所选项目。如果我应该用另一种方式来做这件事,请让我了解一下 模型 看法 角色 @ListBoxFor(m=>m.Roles,新的SelectList(Enum.GetValues(typeof(LiveReport.Domain.Enum.UserRoles))) 角色是一个复杂的对象。ListBoxFor发送与所选值对应的简单字符串列表 因此,您可以拥有一个属性来保存选定的值: public virtual IList<string> S

当用户在角色中选择项目并提交时,模型不会填充所选项目。如果我应该用另一种方式来做这件事,请让我了解一下

模型

看法

角色
@ListBoxFor(m=>m.Roles,新的SelectList(Enum.GetValues(typeof(LiveReport.Domain.Enum.UserRoles)))

角色
是一个复杂的对象。ListBoxFor发送与所选值对应的简单字符串列表

因此,您可以拥有一个属性来保存选定的值:

public virtual IList<string> SelectedRoles { get; set; }
此外,您似乎正在使用一些枚举来填充选择列表项。因此,您可以使用与属性相同的枚举将列表绑定到:

public virtual IList<UserRoles> SelectedRoles { get; set; }
公共虚拟IList SelectedRoles{get;set;}
仍然不绑定它们,使用在角色的用户列表框中未选择用户上的任何角色。
        <label>Roles</label>
        @Html.ListBoxFor(m => m.Roles, new SelectList(Enum.GetValues(typeof(LiveReport.Domain.Enum.UserRoles))))
public virtual IList<string> SelectedRoles { get; set; }
@Html.ListBoxFor(
    m => m.SelectedRoles, 
    new SelectList(
        Enum.GetValues(typeof(LiveReport.Domain.Enum.UserRoles))
    )
)
public virtual IList<UserRoles> SelectedRoles { get; set; }