阅读相关资料 - ASP.NET MVC with EF Core

问题描述 投票:0回答:0

我试图在单击详细信息时显示我的成分,但它不起作用。 但是当你点击“详细信息”时,它会进入一个空白屏幕。

``

`   public class Recipe
    {
        [Key]
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        [ValidateNever]
        public string ImageUrl { get; set; }
        [ValidateNever]
        public ICollection<RecipeIngredient> RecipeIngredient { get;}
      
    }

public class RecipeIngredient
{
    public int Id { get; set; }
    public int IngredientId { get; set; }
    [ValidateNever]
    public Ingredient Ingredient { get; set; }
    public int RecipeId { get; set; }
    [ValidateNever]
    public Recipe Recipe { get; set; }
}
     public class Ingredient
        {
        [Key]
        public int Id { get; set; }
        
        public string Name { get; set; }
  
        public int UnitOfMeasureId { get; set; }
        [ValidateNever]
        public UnitOfMeasure UnitOfMeasure { get; set; }
        
        public int QuantityOfMeasureId { get; set; }
        [ValidateNever]
        public QuantityOfMeasure QuantityOfMeasure { get; set; }
        

      }

      public IActionResult Details(int? id)
        {
            if (id == null || id == 0)
            {
                return NotFound();
            }
            var ingredients = _context.Recipes.Include(u => `u.RecipeIngredient).ThenInclude(e=>e.Ingredient)
.
AsNoTracking().FirstOrDefault(m=>m.Id == id);`
            if(ingredients == null)
            {
                return NotFound();
            }
            return View(ingredients);
        }


``

我的 Details 方法有问题吗?但是当你点击“详细信息”时,它会进入一个空白屏幕。

Details方法有问题吗?在调试模式下,配方成分计数为 0.

asp.net-mvc entity-framework
© www.soinside.com 2019 - 2024. All rights reserved.