【问题标题】:how to modify the routes?如何修改路线?
【发布时间】:2011-08-28 11:12:08
【问题描述】:

我有 asp.net mvc 项目,它的结构和路由如下。

“Site.Master”包含图片和css文件,路径:

  • ../../Images/1.gif
  • ../../Content/site.css.

当访问页面“http://www.localhost.com/Info/Index/1001”时,它可以工作。

但是页面“http://www.localhost.com/Info/Index/1001/1”或“http://www.localhost.com/Info/Index/1001/2”,不要。

我修改了 Site.Master 中的图片和 css 文件路径,如:

  • /Images/1.gif
  • /Content/site.css

另外,有没有其他方法可以修复?或者修改路由?因为,我想在iis中使用虚拟目录部署。

-> 图片

  • 1.gif
  • 2.jpg

-> 内容

  • site.css

-> 观看次数

  • 首页

    -- 索引.aspx

  • 信息

    -- 索引.aspx

  • 共享

    -- Site.Master

    routes.MapRoute( "InfoPagedRoute", "{controller}/{action}/{classid}/{page}", 新的 { 控制器 = “信息”,动作 = “索引”,classid = @“\d{1,10}”,页面 = 1 } );

【问题讨论】:

    标签: model-view-controller routes


    【解决方案1】:

    你原来的路线:

    routes.MapRoute(
         "InfoPagedRoute",
         "{controller}/{action}/{classid}/{page}", 
         new { controller = "Info", action = "Index", classid = @"\d{1,10}", page = 1 } 
    );
    

    您似乎正在尝试在 classid 的路由默认值中使用验证器,因此您需要包含验证参数或为 classid 设置默认值。

    我建议:

    routes.MapRoute(
         "InfoPagedRoute",
         "{controller}/{action}/{classid}/{page}", 
         new { controller = "Info", action = "Index", classid = 1001, page = 1 } 
    );
    

    如果更新路线不能解决问题,您可以使用 Phil Haack 的 route debugger。这对于确定您期望被击中的路线是否真的是正在使用的路线非常有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-12
      • 2017-01-09
      • 1970-01-01
      • 2013-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多