0
リストボックスのアイテムをコントローラに戻しています。 私のコントローラは常に空です。 List.Itとして別の変数を宣言すると、選択した値だけが返されます。私はすべての値を返す。MVC 5はすべてのリストボックスアイテムをコントローラに渡します
私はそれらの間で項目を転送するためにjqueryを使用する2つのリストボックスを持っています。ここ
$('#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();
});
は実際にフォームデータ内の1つの入力がちょうど1値をコントローラに転送することができビュー
@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; }