0

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.

2 Answers 2

2

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)

Sign up to request clarification or add additional context in comments.

Comments

0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.