Domanda

I am creating a MVC web application.

At the moment I have this in the controller:

                                    People =
                                        new SelectList(
                                        this.peopleManager
                                        .GetPeople(), 
                                        "Id", 
                                        "Name"), 

And this in the View:

<div class="form-group">
    @Html.LabelFor(model => model.SearchCriteria.PeopleIds, "Person", new { @class = "col-md-12" })
    <div class="col-md-12">
        @Html.ListBoxFor(model => model.SearchCriteria.PeopleIds, this.Model.PeopleViewModel.People, new { @class = "form-control cascade-people" })
        @Html.ValidationMessageFor(model => model.SearchCriteria.PeopleIds, null, new { @class = "text-danger" })
    </div>
</div>

This works perfectly, but I need to change the "SelectList" to a "List" that displays the elements as text in a list with bullet points, not as elements in a listbox.

I'm not sure how to convert this? Any help would be greatly appreciated.

È stato utile?

Soluzione

This should be really simple.

First of all in your model you would need to change People to a List rather than a select list.

Then you populate that list with the data you require.

Then in the view you simply loop through something like this:

 <ul>
     @foreach (var person in Model.People){
        <li>person.id person.name</li>
     }
 </ul>

That is assuming i have understood your question correctly!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top