Pretty simple..or so I thought. This is a plugin page in NopCommerce but I don't think that is at play here.
My Models:
public class CheckBoxModel
{
public string Name { get; set; }
public bool Checked { get; set; }
}
public partial class ContactUsModel : BaseNopModel
{
[AllowHtml]
[DisplayName("Case Type")]
public List<CheckBoxModel> CaseType { get; set; }
}
My Controller for a quick check to see if form is displaying correctly:
var model = new ContactUsModel
{
CaseType = new List<CheckBoxModel>()
{
new CheckBoxModel() { Name="Civil Tax", Checked=false },
new CheckBoxModel() { Name="Criminal Tax", Checked=false },
new CheckBoxModel() { Name="Other Tax", Checked=false }
}
}
My razor:
<div class="inputs">
@Html.LabelFor(model => model.CaseType)
@for(int i = 0; i < Model.CaseType.Count; i++)
{
@Html.LabelFor(lbl => lbl.CaseType[i].Name)
@Html.CheckBoxFor(chk => chk.CaseType[i].Checked)
}
</div>
HTML:
Case Type: Name [] Name[] Name[]
What am I missing to get the actual name assigned in the controller to show??