0

I have the following select control in my view:

<select id="countriesMultiselect" name="countriesMultiselect" multiple="multiple"
            style="width: 180px; font-size: 10px; text-align: left;">
            @foreach (var region in Model.RegionsHierarchy)
            {
                if (region.Children != null && region.Children.Count > 0)
                {
                <optgroup id="@region.MdsId" label="@region.Name">
                    @foreach (var childRegion in region.Children)
                    {
                        <option id="@childRegion.MdsId">@childRegion.Name</option>
                    }
                    @*</option>*@
                </optgroup>
                }
                else
                {
                <option id="@region.MdsId">@region.Name</option>
                }
            }
        </select>

When I click the submit button, the controller's action is called:

    public RedirectToRouteResult Search(SearcherViewModel model)
            {
 //do some stuff   
                return RedirectToAction("Index");
            }

How can I get the selected items?

niao
  • 4,972
  • 19
  • 66
  • 114

1 Answers1

0

I would recommend you replacing this tag soup with a custom html helper that will handle this for you.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • actually I cannot use it now. Can you please give me a suggestion what can I do to have a selected items in my model? – niao Jan 17 '12 at 20:32
  • @niao, there is no reason why you cannot use it. I really wouldn't like to give bad advices on Stack Overflow as other people having the same problem might actually do the same thing as you which I consider wrong. I have already provided my recommendation. If you don't like it, I appreciate your opinion and wish you good luck in solving the issue. – Darin Dimitrov Jan 17 '12 at 20:34
  • do you have an idea how the custom html helper can be used with jquery UI multiselect? http://www.erichynds.com/jquery/jquery-ui-multiselect-widget/ – niao Jan 17 '12 at 22:07
  • @niao, jQuery multiselect is a client side plugin that really doesn't care about what server side technology you have used on your server to generate the markup. In your case you would be using ASP.NET MVC with the custom HTML helper that will spit the markup that this plugin expects. – Darin Dimitrov Jan 17 '12 at 22:11