Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在视图中创建列表以添加到模型';s ICollection属性_Asp.net Mvc_Entity Framework 6 - Fatal编程技术网

Asp.net mvc 在视图中创建列表以添加到模型';s ICollection属性

Asp.net mvc 在视图中创建列表以添加到模型';s ICollection属性,asp.net-mvc,entity-framework-6,Asp.net Mvc,Entity Framework 6,我试图创建一个网站,允许用户上传食谱 所以我有一个名为Recipe的模型类,它如下所示 [Table("Recipe")] public class Recipe { public int ImageMimeType { get; set; } public byte[] Thumbnail { get; set; } [Key] [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]

我试图创建一个网站,允许用户上传食谱

所以我有一个名为Recipe的模型类,它如下所示

[Table("Recipe")]
public class Recipe
{
    public int ImageMimeType { get; set; }
    public byte[] Thumbnail { get; set; }

    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int RecipeID { get; set; }
    public string BakeryName { get; set; }
    public string Description { get; set; }
    public byte[] ImageData { get; set; }
    public int EndorsementCount { get; set; }
    public DateTime LastModified { get; set; }

    [Required]
    public int UserId { get; set; }

    public virtual ICollection<Ingredient> Ingredients { get; set; }
    public virtual ICollection<Method> Methods { get; set; }


}
在我看来,我希望动态添加配料:用户在需要时单击“添加”按钮添加另一种配料

我的问题是: 在提交表单时,我应该如何在视图中创建成分列表并将其传递给控制器的创建方法

问题是,由于RecipeID是自动生成的,我不知道在视图中我的RecipeID是什么,直到我将我的配方保存到数据库表中。但是我如何将这个配方传递给我的每一种配料呢


任何帮助都将不胜感激

在首次保存
配方之前,您无法保存
配料
[Table("Ingredient")]
public class Ingredient
{
    [Key]
    public int IngredientID { get; set; }

    [Required]
    public int RecipeID { get; set; }

    public string ItemName { get; set; }
    public int Measurement { get; set; }
    public string MeasurementUnit { get; set; }
}