【发布时间】:2016-12-27 06:14:26
【问题描述】:
我正在尝试将列表框中的项目传递回控制器。 我的控制器总是空的。如果我为它声明另一个变量为 List.It 只传回选定的值。我想传回所有的值。
我有 2 个列表框,我使用 jquery 在它们之间传输项目。
$('#btnRight').click(function (e) {
var selectedOpts = $('#CurrentRoles option:selected');
if (selectedOpts.length == 0) {
alert("Nothing to move.");
e.preventDefault();
}
$('#ListOfRoles').append($(selectedOpts).clone());
$(selectedOpts).remove();
e.preventDefault();
});
$('#btnLeft').click(function(e) {
var selectedOpts = $('#ListOfRoles option:selected');
if (selectedOpts.length == 0) {
alert("Nothing to move.");
e.preventDefault();
}
$('#CurrentRoles').append($(selectedOpts).clone());
$(selectedOpts).remove();
e.preventDefault();
});
这是我的查看代码
@Html.ListBox("CurrentRoles", new SelectList(Model.CurrentRoles, "Key", "Value"), new { id = "CurrentRoles" })
public ActionResult Edit(UserRolesmanagement role,List<string> CurrentRoles)
{
//logic
}
型号
public UserRolesmanagement()
{
user = new ApplicationUser();
ListOfRoles = new List<IdentityRole>();
CurrentRoles = new Dictionary<string, string>();
ListOfUsers = new List<ApplicationUser>();
}
public ApplicationUser user { get; set; }
public Dictionary<string,string> CurrentRoles { get; set;}
public List<IdentityRole> ListOfRoles { get; set; }
public List<ApplicationUser> ListOfUsers { get; set; }
【问题讨论】:
标签: c# jquery asp.net-mvc model-view-controller listbox