I have a list of model instances inside my main model. How are these "sub-models" in the list stored? My models in the list also contain a list. Are these stored by base, reference, or value?
In essence, I capture my current model and store it to a list within the current model and allow users to re-fill the model with new data. Because I capture the whole model I am also getting the list. I have no issues with overflows, so I'm wondering how the models in the list are stored.
I have a model with a list of models with lists of models with lists of models....
Thanks in Advance.
in your model:
public class Model
{
public Model()
{
SubModels = new List<SubModel>();
}
public IList<SubModel> SubModels { get; set; }
}
public class SubModel
{
public int Id { get; set; }
public string Name{ get; set; }
}
in razor view
@for (int i = 0; i < Model.SubModels.Count; i++)
{
<div id="tabs-@(i)">
@Html.HiddenFor(model => Model.SubModels[i].Id)
<div>
Name
</div>
<div>
@Html.TextBoxFor(model => Model.SubModels[i].Name)
</div>
</div>
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.