[英]Lists of Model Copies in a Model MVC 4 C# 4
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>
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.