asp.net mvc routing id parameter

前端 未结 6 880
自闭症患者
自闭症患者 2020-12-29 07:04

I am working on a website in asp.net mvc. I have a route

routes.MapRoute(
    \"Default\", // Route name
    \"{controller}/{action}/{id}\", // URL with pa         


        
6条回答
  •  自闭症患者
    2020-12-29 07:58

    Option 1

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    
    public ActionResult ErrorPage(int id)
    {
        return View();
    }
    

    Option 2

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{errorno}",
        new { controller = "Home", action = "Index", errorno = UrlParameter.Optional }
    );
    
    public ActionResult ErrorPage(int errorno)
    {
        return View();
    }
    

    Option 3

    routes.MapRoute(
        "Default",
        "{controller}/{action}/{id}",
        new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    
    public ActionResult ErrorPage(int id)
    {
        int errorno = id;
        return View();
    }
    

提交回复
热议问题