WagnerMaurer
WagnerMaurer

Reputation: 78

ListBox in ASP.NET MVC 3

Someone knows how to create a ListBox in ASP.NET MVC 3 who will pass the selected checkboxs, for example, for the controller? I'm thankful for your help.

I have created this:

@Html.ListBox("selTipoVinculoTipoConvenio", new SelectList(Model.TIPO, "ID_TIPO_CONVENIO", "TXT_DESCRICAO"), new { @id = "selTipoVinculoTipoConvenio", @name = "selTipoVinculo", @class = "select-multiple w-464", multiple = "multiple", @data_width = "464" })

But now I need to create a filter with the selected checkboxs...

Just know a little bit about HTML Helpers of C# Razor.

Upvotes: 0

Views: 552

Answers (2)

Zbigniew
Zbigniew

Reputation: 27594

You can use Html.CheckBox or Html.CheckBoxFor methods to create checkbox. However this method works only for a single variable, for multiple values (lists, arrays etc) you will have to use a loop, so it may be better to create editor template for your variable (Html.EditorFor)

Upvotes: 2

JC Lizard
JC Lizard

Reputation: 1056

do it manually. Listbox helper just creates a element for you.

create a select element and use the model to poupate it:

<select multiple="multiple">
   @foreach(var item in model){
       string checked="";
       if(model.checked){checked="checked='checked'"};

       <option value="@model.id" @checked>@model.name</option>
   }

</select>

Upvotes: 0

Related Questions