Asp.net mvc 在视图中创建列表以添加到模型';s ICollection属性
我试图创建一个网站,允许用户上传食谱 所以我有一个名为Recipe的模型类,它如下所示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)]
[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; }
}