这是我的产品控制器的笔记本电脑操作。 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);
}
我认为,您需要检查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 }
);
}