C# 从数据库中删除模型投标记录集合
我正在使用以下模型绑定代码集合在数据库中添加记录。现在我想删除数据库中的记录。如何从数据库中删除模型绑定集合。如何通过实体框架删除C# 从数据库中删除模型投标记录集合,c#,asp.net-mvc,entity-framework,C#,Asp.net Mvc,Entity Framework,我正在使用以下模型绑定代码集合在数据库中添加记录。现在我想删除数据库中的记录。如何从数据库中删除模型绑定集合。如何通过实体框架删除 public class CreateRecipeModel { Public int Id // This is primary key //required public string Name { get; set; } public IList<IngredientModel> Ingredients {
public class CreateRecipeModel
{
Public int Id // This is primary key
//required
public string Name { get; set; }
public IList<IngredientModel> Ingredients { get; set; }
}
public class IngredientModel
{
Public int Id // This is primary key
//required
public string Quantity { get; set; }
Public int NId { get; set; }// This is foriegn key of Parent table
}
public类CreateRecipeModel
{
Public int Id//这是主键
//必需的
公共字符串名称{get;set;}
公共IList元素{get;set;}
}
公共类IngCreditModel
{
Public int Id//这是主键
//必需的
公共字符串数量{get;set;}
Public int NId{get;set;}//这是父表的外键
}
看法
@Html.EditorFor(model=>model.Name)
@Html.ValidationMessageFor(modelItem=>model=>model.Name)
对于(var i=0;imodelItem.Components[i].Id)
@EditorFor(modelItem=>modelItem.Components[i].Quantity)
@Html.ValidationMessageFor(modelItem=>modelItem.Components[i].Quantity)
}
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(modelItem => model => model.Name)
<input type=”button” value=”Add” class=”AddQuantity”/>
for (var i = 0 ; i < Model.Count(); i++)
{
@Html.HiddenFor(modelItem => modelItem.Ingredients[i].Id)
@Html.EditorFor(modelItem => modelItem.Ingredients[i].Quantity)
@Html.ValidationMessageFor(modelItem => modelItem.Ingredients [i].Quantity)
}
<input type=”button” value=”delete” class=”deleteModelBinding”/>