gaganHR
gaganHR

Reputation: 337

Populate a Checkbox list from a view model list

I am trying to re define the select query and make it user defined by first listing out all the fields in one checkbox list and grouping them in another and providing a where condition for selected check boxed fields. I am returning a view model that contains the list of all my columns. I need to know how to populate the list from my view model onto a asp.net checkbox list.

Thanks in advance, Hrg

Upvotes: 0

Views: 505

Answers (2)

Janki
Janki

Reputation: 501

You van use this also

@for (int i = 0; i < Model.PropertyName.Count(); i++) {

    @Html.CheckBoxFor(model => Model.Tags[i])

}

Upvotes: 1

Amit
Amit

Reputation: 15387

As per my understanding try this

@for (int i = 0; i < Model.PropertyName.Count(); i++)
    {
        <p>
        @Html.CheckBox("model.PropertyName[" + i + "]", !Model.PropertyName[i])
        </p>
    }

Upvotes: 1

Related Questions