Asp.Net MVC5操作在参数中获取ID,但在主体中获取ID

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

这是我的产品控制器的笔记本电脑操作。 ID参数通常从上一个视图获取ID。但是,当我要使用它(var idi = ID)时,它变为0。为什么?

// GET: Product/notebooks/1
        [Route("Product/Notebooks/{ID}")]
        public ActionResult Notebooks(int ID)
        {
            int  idi = ID;
            var producer = dbProtel.Computers.SingleOrDefault(p => p.Producers.ID == ID);

            var vm = Methods.Methodss.createVM();
            return View(vm);

        }
asp.net asp.net-mvc-5 actionresult
1个回答
0
投票

我认为,您需要检查RegisterRoutes()方法

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
© www.soinside.com 2019 - 2024. All rights reserved.