小编Har*_*Ado的帖子

在 razor 页面无法正常工作的 asp.net core 中创建级联下拉列表

我正在尝试首先使用 asp.net core 3.1 代码实现级联下拉列表。我有两张表,分别是车辆品牌和车辆型号。第一个下拉列表将填充品牌,选择任何品牌后,第二个下拉列表将填充型号。但我在模型下拉列表中一直未定义。下面是我的实现。请问我做错了什么?谢谢

汽车服务接口

    
    namespace Application.Common.Interfaces
    {
       public interface IVehicleService
       {
         IEnumerable<VehicleMake> GetMakes();
         IEnumerable<VehicleModel> GetModels(int categoryId);
       }
     }
Run Code Online (Sandbox Code Playgroud)

车辆服务


    namespace Application.Common.Interfaces
    {
      public class VehcicleService : IVehicleService
      {
        private readonly IApplicationDbContext _dbContext;
        public VehcicleService(IApplicationDbContext dbContext)
        {
            _dbContext = dbContext;
        }
        public IEnumerable<VehicleMake> GetMakes()
        {
            IEnumerable<VehicleMake>  makes = _dbContext.VehicleMakes.ToList();
            return makes;       
        }
        public IEnumerable<VehicleModel> GetModels(int MakeId)
        {
            IEnumerable<VehicleModel> model = _dbContext.VehicleModels.Where(x => x.VehicleMakeId == MakeId).ToList();            
            return model;
        }
    }
     }
Run Code Online (Sandbox Code Playgroud)

我的模型页面

namespace Wbc.WebUI.Areas.Tools.Pages
{
    
    public class SearchByMakeModel : PageModel …
Run Code Online (Sandbox Code Playgroud)

sql-server ajax asp.net-core clean-architecture razor-pages

0
推荐指数
1
解决办法
4482
查看次数