I have a list of checkboxes and I need to bind values that are strings (@ item.SelectedValue) with my IEnumerable>.
<div class="editor-field perfil-filtro-expander-todasAcoes">
<div class="metro perfil-filtro-expander-overflow todasAcoes" id="todasAcoes" name="todasAcoes">
@foreach (DetailedLookupModel<string> item in (IEnumerable<DetailedLookupModel<string>>)ViewBag.Acoes)
{
<div style="padding-bottom: 10px;">
@*<input id="@item.SelectedValue" type="checkbox" name="@item" value="@item.SelectedValue"/>*@
@Html.TextBoxFor(x => Model.Acoes, new { @type = "checkbox", @id = item.SelectedValue, @value = item.SelectedValue})
<label for="@item.SelectedValue">
<b>@item.Title</b>
<br />
<span class="perfil-filtro-expander-descricao">
@item.Description
</span>
</label>
</div>
}
</div>
@Html.ValidationMessageFor(model => model.Descricao)
</div>
Model Property:
[DisplayName("Ações")]
[Required]
public IEnumerable<DetailedLookupModel<String>> Acoes { get; set; }
In this way I can get the checboxes, but the value of them that was to be "value"
comes with null
. Also I can not make changes to the labels, as my css depends on those ids
to understand what the labels are for the appropriate fields.