Wednesday, April 10, 2013

How to get/set Selected Values of Select2 Multi Selection List in MVC?

Hi 
Here  you  can  get  selected element of  Multi selection list  using  Select2 Jqyery.

Jquery Code

var AuthorList=  $("select#AuthorList").select2("val");
-----------------------------------------------------------------------

2. How to set MultiSelection List?

    First  Get  Selected  value  from  your  database  and  add  into   Hidden Field
like.



Then
Var authlist="";
  var a_options = [];

        $.each($("#AuthorListoption"), function () {
            if (authlist.toLowerCase().indexOf($(this).attr("value")) >= 0) {
                a_options.push($(this).attr("value"));
            }

        });

        $("select#AuthorList").select2("val", a_authlist);

HAPPY CODING



2 comments:

  1. Can you tell me, how we can get the values of the selected item to an array or to some other thing, which can then be post back to asp.net for further processing like to add to a database etc.

    ReplyDelete