从数据库中删除模型招标记录的集合

时间:2016-06-17 11:27:32

标签: 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 { 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
}

查看

@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”/>

0 个答案:

没有答案