Multiple selection with listboxfor/listbox post only last selected itemListBoxFor not letting me select multiple items MVCListboxfor MVC3 Razor. User selection from database fieldsMVC 3 - Getting all selected values from a listbox on postbackHow do you properly create a MultiSelect <select> using the DropdownList helper?MVC4 - Setting Initially Selected Item in DropDownListMVC 3.5/Razor: Listbox + Option 'Selected' Value is being IgnoredWhy are the initial multiple selections of an Html.ListBox not visible?Select ListBox items using comma separated values in mvc?Error while posting dropdownAjax request not returning success from controllerHow to produce 'n' no. of text boxes having different Names with respect to no. of drop down items selected?
Identify a problem where a potentially winning move draws because of the 50 move rule
Couple of slangs I've heard when watching anime
Dealing with an extrovert co-worker
Efficiently pathfinding many flocking enemies around obstacles
Can more than one wizard copy a spell from a spellbook?
Would this system work to purify water?
How to get the current pages Page Design in code
Handling Disruptive Student on the Autistic Spectrum
If the first law of thermodynamics ensures conservation of energy, why does it allow systems to lose energy?
Non-visual Computers - thoughts?
What is the history of the university asylum law?
Shouldn't the "credit score" prevent Americans from going deeper and deeper into personal debt?
Slitherlink Fillomino hybrid
Who was president of the USA?
Is immersion of utensils (tevila) valid before koshering (hagala)?
Why did Khan ask Admiral James T. Kirk about Project Genesis?
What is the difference between "Grippe" and "Männergrippe"?
Does travel insurance for short flight delays exist?
How would one country purchase another?
Can roasted coffee as soil burn soft leaves?
Is “I am getting married with my sister” ambiguous?
Disambiguation of "nobis vobis" and "nobis nobis"
Can't stopover at Sapporo when going from Asahikawa to Chitose airport?
Which note goes on which side of the stem?
Multiple selection with listboxfor/listbox post only last selected item
ListBoxFor not letting me select multiple items MVCListboxfor MVC3 Razor. User selection from database fieldsMVC 3 - Getting all selected values from a listbox on postbackHow do you properly create a MultiSelect <select> using the DropdownList helper?MVC4 - Setting Initially Selected Item in DropDownListMVC 3.5/Razor: Listbox + Option 'Selected' Value is being IgnoredWhy are the initial multiple selections of an Html.ListBox not visible?Select ListBox items using comma separated values in mvc?Error while posting dropdownAjax request not returning success from controllerHow to produce 'n' no. of text boxes having different Names with respect to no. of drop down items selected?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to do a multiple selection with ListBoxFor of Razor, but the select does not allow me to select multiple items (I can do that only selecting my items with Ctr+click the second item). I've reduced my code to minimal like the exemple shown in this answer (my code is above). Anyone can help me?? I'm desperate.
My Model
public IEnumerable<int> ParoleChiave get; set;
public IEnumerable<SelectListItem> ListaParoleChiave get; set;
My Controller
model.ListaParoleChiave = new List<SelectListItem>()
new SelectListItem() Text = "Pro", Value = "2",
new SelectListItem() Text = "Test", Value = "3"
;
My View
<div class="form-group form-group-sm">
<label class="col-xs-12">Parole chiave</label>
<div class="col-xs-12">
@Html.ListBoxFor(m => m.ParoleChiave, Model.ListaParoleChiave, new @class = "form-control", style = "width: 100%" )
</div>
</div>
c# razor model-view-controller multi-select html.listboxfor
add a comment |
I'm trying to do a multiple selection with ListBoxFor of Razor, but the select does not allow me to select multiple items (I can do that only selecting my items with Ctr+click the second item). I've reduced my code to minimal like the exemple shown in this answer (my code is above). Anyone can help me?? I'm desperate.
My Model
public IEnumerable<int> ParoleChiave get; set;
public IEnumerable<SelectListItem> ListaParoleChiave get; set;
My Controller
model.ListaParoleChiave = new List<SelectListItem>()
new SelectListItem() Text = "Pro", Value = "2",
new SelectListItem() Text = "Test", Value = "3"
;
My View
<div class="form-group form-group-sm">
<label class="col-xs-12">Parole chiave</label>
<div class="col-xs-12">
@Html.ListBoxFor(m => m.ParoleChiave, Model.ListaParoleChiave, new @class = "form-control", style = "width: 100%" )
</div>
</div>
c# razor model-view-controller multi-select html.listboxfor
add a comment |
I'm trying to do a multiple selection with ListBoxFor of Razor, but the select does not allow me to select multiple items (I can do that only selecting my items with Ctr+click the second item). I've reduced my code to minimal like the exemple shown in this answer (my code is above). Anyone can help me?? I'm desperate.
My Model
public IEnumerable<int> ParoleChiave get; set;
public IEnumerable<SelectListItem> ListaParoleChiave get; set;
My Controller
model.ListaParoleChiave = new List<SelectListItem>()
new SelectListItem() Text = "Pro", Value = "2",
new SelectListItem() Text = "Test", Value = "3"
;
My View
<div class="form-group form-group-sm">
<label class="col-xs-12">Parole chiave</label>
<div class="col-xs-12">
@Html.ListBoxFor(m => m.ParoleChiave, Model.ListaParoleChiave, new @class = "form-control", style = "width: 100%" )
</div>
</div>
c# razor model-view-controller multi-select html.listboxfor
I'm trying to do a multiple selection with ListBoxFor of Razor, but the select does not allow me to select multiple items (I can do that only selecting my items with Ctr+click the second item). I've reduced my code to minimal like the exemple shown in this answer (my code is above). Anyone can help me?? I'm desperate.
My Model
public IEnumerable<int> ParoleChiave get; set;
public IEnumerable<SelectListItem> ListaParoleChiave get; set;
My Controller
model.ListaParoleChiave = new List<SelectListItem>()
new SelectListItem() Text = "Pro", Value = "2",
new SelectListItem() Text = "Test", Value = "3"
;
My View
<div class="form-group form-group-sm">
<label class="col-xs-12">Parole chiave</label>
<div class="col-xs-12">
@Html.ListBoxFor(m => m.ParoleChiave, Model.ListaParoleChiave, new @class = "form-control", style = "width: 100%" )
</div>
</div>
c# razor model-view-controller multi-select html.listboxfor
c# razor model-view-controller multi-select html.listboxfor
edited Mar 27 at 17:38
user3692982
asked Mar 27 at 17:29
user3692982user3692982
53 bronze badges
53 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I found the error. It's not depending from my ListBoxFor element, it was caused by the js code that I wrote to post to the server action my formData with additional data.
Basically it was like:
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
d[pair[0]] = pair[1];
return d;
I realized that the multiple values where posting like two entries (key/value pairs) of the FormData but with the same key name, so my code was overwriting the first entry with the second. I replaced with the code above and now it works like a charm.
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
var occurenceOfKey = Array.from(fd.keys()).reduce(function (n, val)
return n + (val === pair[0]);
, 0);
if (occurenceOfKey > 1)
d[pair[0]] = fd.getAll(pair[0]);
else
d[pair[0]] = pair[1];
return d;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383285%2fmultiple-selection-with-listboxfor-listbox-post-only-last-selected-item%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I found the error. It's not depending from my ListBoxFor element, it was caused by the js code that I wrote to post to the server action my formData with additional data.
Basically it was like:
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
d[pair[0]] = pair[1];
return d;
I realized that the multiple values where posting like two entries (key/value pairs) of the FormData but with the same key name, so my code was overwriting the first entry with the second. I replaced with the code above and now it works like a charm.
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
var occurenceOfKey = Array.from(fd.keys()).reduce(function (n, val)
return n + (val === pair[0]);
, 0);
if (occurenceOfKey > 1)
d[pair[0]] = fd.getAll(pair[0]);
else
d[pair[0]] = pair[1];
return d;
add a comment |
I found the error. It's not depending from my ListBoxFor element, it was caused by the js code that I wrote to post to the server action my formData with additional data.
Basically it was like:
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
d[pair[0]] = pair[1];
return d;
I realized that the multiple values where posting like two entries (key/value pairs) of the FormData but with the same key name, so my code was overwriting the first entry with the second. I replaced with the code above and now it works like a charm.
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
var occurenceOfKey = Array.from(fd.keys()).reduce(function (n, val)
return n + (val === pair[0]);
, 0);
if (occurenceOfKey > 1)
d[pair[0]] = fd.getAll(pair[0]);
else
d[pair[0]] = pair[1];
return d;
add a comment |
I found the error. It's not depending from my ListBoxFor element, it was caused by the js code that I wrote to post to the server action my formData with additional data.
Basically it was like:
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
d[pair[0]] = pair[1];
return d;
I realized that the multiple values where posting like two entries (key/value pairs) of the FormData but with the same key name, so my code was overwriting the first entry with the second. I replaced with the code above and now it works like a charm.
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
var occurenceOfKey = Array.from(fd.keys()).reduce(function (n, val)
return n + (val === pair[0]);
, 0);
if (occurenceOfKey > 1)
d[pair[0]] = fd.getAll(pair[0]);
else
d[pair[0]] = pair[1];
return d;
I found the error. It's not depending from my ListBoxFor element, it was caused by the js code that I wrote to post to the server action my formData with additional data.
Basically it was like:
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
d[pair[0]] = pair[1];
return d;
I realized that the multiple values where posting like two entries (key/value pairs) of the FormData but with the same key name, so my code was overwriting the first entry with the second. I replaced with the code above and now it works like a charm.
data: function (d)
var fd = new FormData(myForm[0]);
for (var pair of fd.entries())
var occurenceOfKey = Array.from(fd.keys()).reduce(function (n, val)
return n + (val === pair[0]);
, 0);
if (occurenceOfKey > 1)
d[pair[0]] = fd.getAll(pair[0]);
else
d[pair[0]] = pair[1];
return d;
answered Mar 27 at 19:08
user3692982user3692982
53 bronze badges
53 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55383285%2fmultiple-selection-with-listboxfor-listbox-post-only-last-selected-item%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown