【发布时间】:2019-08-25 10:03:18
【问题描述】:
我有 3 个模型(Briefing、ligne、voie),每个模型都有一个子模型列表。如何将其管理到视图中以添加/删除项目?
public class Briefing
{
public int Id { get; private set; }
public Guid GuidBriefing { get; set; }
public int Version { get; set; }
public List<Ligne> Lignes { get; set; }
public string Libelle { get; set; }
public string Description { get; set; }
}
public class Ligne
{
public int Id { get; set; }
public string Libelle { get; set; }
public List<VoieObject> Voies { get; set; }
}
public class VoieObject
{
public int Id { get; set; }
public string Libelle { get; set; }
public int Vitesse { get; set; }
public string PointKilometrique { get; set; }
public string PointKilometriqueFin { get; set; }
}
我使用实体框架,我想知道如何使用 MVC 5 将这些模型管理到视图中,以便在每个模型的列表中添加或删除项目。
例如:对于Briefing,如何在带有视图的列表中添加新项目“Ligne”。
供参考,我不能用这种写法:
@Html.LabelFor(model => model.FavouriteMovies[i].Title)
@Html.EditorFor(model => model.FavouriteMovies[i].Title)
@Html.ValidationMessageFor(model => model.FavouriteMovies[i].Title)
我必须使用:
<label for="FavouriteMovies_0__Title">Title</label>
<input id="FavouriteMovies_0__Title" name="FavouriteMovies[0].Title" type="text" value="" />
<span class="field-validation-error">The Title field is required.</span>
我也查看了这篇文章: Add item into List from View and pass to Controller in MVC5
但我不知道我提交表单时生成的 Json 是否会正确保存我的数据。
感谢您的帮助和好意:)
【问题讨论】:
标签: c# entity-framework view asp.net-mvc-5 model