I will be presenting my users a form to fill out a form to get some quotes. There will be a series of objects (~15 or so) that I want to present as check boxes. The issue is, I don't want to hardcode in 15 bools, I want them to be dynamically built on a per-user basis. So a simplified version of the model I came up with would look something like this:
public class InqueryViewModel
{
public string Origin { get; set; }
public string Destination { get; set; }
public decimal Weight { get; set; }
public IEnumerable<Option> AdvancedOptions { get; set; }
}
public class Option
{
public bool Selected { get; set; }
public string Type { get; set; }
}
The problem is, I can't figure out how to bind the AdvancedOptions. I tried this:
@foreach (var option in Model.AdvancedOptions)
{
<div class="col-xs-4">
<div class="col-xs-1">
@Html.CheckBoxFor(x => option.Selected)
</div>
<div class="col-xs-2">
@option.Type
</div>
<div class="col-xs-1"></div>
</div>
}
But that doesn't work. I'm pretty new to trying to use front-end forms with MVC, so I may just be going about this the wrong way. Any suggestions?