I have some fields which may vary according to type of project. I'm trying to create these fields and take values for them. I tried create labels and TextBoxFor input by iterating inside a foreach loop like this;
<div class="row" id="customerdetailcontent">
@foreach (var detail in customerFields)
{
<div class="form-group">
<label class="col-md-3 control-label">@detail</label>
<div class="col-md-9">
@Html.TextBoxFor(model => model.CustomerDetail, new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CustomerDetail, "", new { @class = "text-danger" })
</div>
</div>
}
</div>
When I click Submit and check the parameter arriving to action inside controller, CustomerDetail list is null.
this is the field declaration inside the model
public List<CustomerDetailModel> CustomerDetail { get; set; }
It's been a while since I wrote Razor, I might be making a simple mistake or trying something impossible. What am I doing wrong?