We have the below model:
public class Sample
{
public int SampleId { get; set; }
public int ToTestId { get; set; }
public int Name { get; set; }
public virtual ICollection<SampleCondition> Child_SampleConditions { get; set; }
}
I am rendering them in my view as below:
@model Sample
@{
string cntlrName = ViewContext.RouteData.GetRequiredString("controller");
List<SampleCondition> sampleConditions = Model.Child_SampleConditions.ToList();
if (d2l.NullOrEmpty(sampleConditions))
{
Model.Child_SampleConditions .Add(new SampleCondition());
}
List<SampleCondition> sampleConditions = Model.Child_SampleConditions as List<SampleCondition>;
}
@Html.ValidationSummary(true)
@Html.d2_HiddenFor(O => O.SampleId)
<div class="@BOOTSTRAP.ROW">
@Html.ManyToOneFieldFor(Model, O => O.ToTestId, allowed: CrudFlag.Editable)
@Html.FieldFor(O => O.Name, allowed: CrudFlag.Editable)
@Html.FieldFor(O => sampleConditions[0].ConditionValue, allowed:CrudFlag.Editable)
</div>
Please look at the third filed in div, sampleConditions[0].ConditionValue. The html input field for this control is rendering with the name "[0].ConditionValue" instead of "Child_SampleConditions[0].ConditionValue". Thats why when I post this form, the Child_SampleConditions are not automatically binded to the model object into post method.
can somebody advise how to render ICollection input field names correctly so that they can automatically gets model binded.
NOTE: Please exclude the custom model binder options.
EDIT: I am providing some more information here. In the ManyToOneFieldFor mehtod, the name retrieved using the below helper:
string fullName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(name);
It just returns, [0].ConditionValue but not Child_SampleConditions[0].ConditionValue.
Please advise..
Thanks.