代码之家  ›  专栏  ›  技术社区  ›  Mick Walker

ASP.NET MVC 3中的路由问题

  •  0
  • Mick Walker  · 技术社区  · 14 年前

    我在global.asax中定义了以下路由:

    routes.MapRoute(
                   "Agreements2", // Route name
                   "Agreements2/{action}/{id}", // URL with parameters
                   new { controller = "Agreements", action = "AgreementSummery", id = UrlParameter.Optional } // Parameter defaults
                   );
                 routes.MapRoute(
                    "Agreements", // Route name
                    "{controller}/{action}/{id}", // URL with parameters
                    new { controller = "Agreements", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                    );
    

    后一条路线运行良好,但我不明白为什么第一条路线不起作用。

    协议控制方的协议汇总方法定义为:

    [HttpGet]
            public ActionResult AgreementSummery(int? id)
            {
    
                AgreementsModel model = new AgreementsModel();
                model.SelectedAgreementID = id.Value;
                return View(model);
            }
    
    1 回复  |  直到 14 年前
        1
  •  1
  •   Travis J    14 年前

    id没有被定义为可选,而是被定义为可以为null。如果为其分配了一个值,则为可选

    public ActionResult AgreementSummery(int? id = null)
    
    推荐文章