genxgeek
genxgeek

Reputation: 13367

How to preselect values in jquery multiselect?

I'm using the following jquery multi-select control ( http://abeautifulsite.net/blog/2008/04/jquery-multiselect/#configuring ) and need to pre-select some values in the dropdown list.

Can I do this with by passing in a comma delimited items list ("valID1,valID2") somehow (any other methods)? I already have a stored list of what was previously selected.

Upvotes: 1

Views: 1020

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039248

Follow my suggestion here and then slightly re-adapt the controller action, like this:

public ActionResult Index()
{
    var model = new MyViewModel
    {
        // preselect the first and the third item but obviously
        // this could be any list of ids
        SelectedValues = new[] { "1", "3" };
    };
    return View(model);
}

Upvotes: 1

Related Questions