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;








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>









share|improve this question
































    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>









    share|improve this question




























      0












      0








      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>









      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 27 at 17:38







      user3692982

















      asked Mar 27 at 17:29









      user3692982user3692982

      53 bronze badges




      53 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0















          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;






          share|improve this answer
























            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
            );



            );













            draft saved

            draft discarded


















            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









            0















            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;






            share|improve this answer





























              0















              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;






              share|improve this answer



























                0














                0










                0









                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;






                share|improve this answer













                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;







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 19:08









                user3692982user3692982

                53 bronze badges




                53 bronze badges





















                    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.



















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해