Ich versuche, meine Elemente in Listbox zurück zum Controller zu übergeben. Mein Controller ist immer leer. Wenn ich eine andere Variable als List deklariere, bekomme ich nur den ausgewählten Wert zurück. Ich möchte alle Werte zurückgeben.MVC 5 alle Listbox-Artikel an Controller übergeben
Ich habe 2 Listbox, die ich jquery verwenden, um die Elemente zwischen ihnen zu übertragen.
$('#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();
});
hier ist mein Code für Ansicht
@Html.ListBox("CurrentRoles", new SelectList(Model.CurrentRoles, "Key", "Value"), new { id = "CurrentRoles" })
public ActionResult Edit(UserRolesmanagement role,List<string> CurrentRoles)
{
//logic
}
Modell
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; }