[RESOLVED]Is there an MVC control suitable for this?

Hello,

I have a list of categories the user can choose from, Ideally I want to display all of them as follows

First Category

Second Category

Third Category

Forth Category

etc

So in other words I want all categories visible on the page now this is where my problem is when the user clicks on any of the categories I need to set the SelectedCategoryId within the model similar to how you do a dropdown in MVC

@Html.DropDownListFor(x => x.SelectedCategoryId, Model.ListCategories, new { @ID = "drpCategories", @class = "form-control" })

But that isn’t suitable for what I want as I need to make all categories visible on the page I was thinking of using a select list Multiple like this Ideally only allowing the user to select one at a time

<select id="form-field-select-2" class="form-control" multiple="multiple">
<option value="1">First Category</option>
<option value="2">Second Category</option>
<option value="3">Third Category</option>
<option value="4">Forth Category</option>
<option value="5">Fifth Category</option>
</select>

But I’m unsure how to wire this up the model so when one of the options is selected it sets SelectedCategoryId and post’s back to the controller automatically to retrieve the sub categories….

Any Help/Examples via fiddles are highly appreciated. (p.s I do not want to use jquery for this)

Add size attribute, it shows as list box

@Html.DropDownListFor(x => x.SelectedCategoryId, Model.ListCategories, new { id = "drpCategories", @class = "form-control",size="10" })

Leave a Reply