需要 MVC 路由帮助

发布于 2024-09-26 17:39:56 字数 387 浏览 2 评论 0原文

我正在尝试在 MVC2 中映射以下路线。

[absoluteUrl]

[absoluteUrl]/[dynamicBlogName]

这两个路由应该映射到相同的控制器/操作结果。

例如 PostController/Index

我还需要映射这些路线。

[absoluteUrl]/post/[dynamicPostName]

[absoluteUrl]/[dynamicBlogName]/post/[dynamicPostName]

这两个路由也应该映射到相同的控制器/操作结果。

例如 PostController/Default

任何帮助将不胜感激。

I'm trying to map the following routes in MVC2.

[absoluteUrl]

[absoluteUrl]/[dynamicBlogName]

These two routes should map to the same controller/actionresult.

e.g PostController/Index

I also need to map these routes.

[absoluteUrl]/post/[dynamicPostName]

[absoluteUrl]/[dynamicBlogName]/post/[dynamicPostName]

These two routes should also map to the same controller/actionresult.

e.g PostController/Default

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤君无依 2024-10-03 17:39:56

我不在 Visual Studio 前面 - 但尝试这样的事情。

routes.MapRoute(
      "Default1",                                   
      "",                           
      new { controller = "PostController", action = "Index", dynamicBlogName = ""} 
);
routes.MapRoute(
      "Default2",                                             
      "{dynamicBlogName}",                          
      new { controller = "PostController", action = "Index", dynamicBlogName = ""  } 
);
routes.MapRoute(
      "Default3",                                         
      "post/{dynamicPostName}",                           
      new { controller = "PostController", action = "Default", dynamicBlogName = "", dynamicPostName="" }
);
routes.MapRoute(
      "Default4",                                            
      "{dynamicBlogName}/post/{dynamicPostName}",            
      new { controller = "PostController", action = "Default", dynamicBlogName = "", dynamicPostName=""  }
);

I'm not in front of Visual Studio - but try something like this.

routes.MapRoute(
      "Default1",                                   
      "",                           
      new { controller = "PostController", action = "Index", dynamicBlogName = ""} 
);
routes.MapRoute(
      "Default2",                                             
      "{dynamicBlogName}",                          
      new { controller = "PostController", action = "Index", dynamicBlogName = ""  } 
);
routes.MapRoute(
      "Default3",                                         
      "post/{dynamicPostName}",                           
      new { controller = "PostController", action = "Default", dynamicBlogName = "", dynamicPostName="" }
);
routes.MapRoute(
      "Default4",                                            
      "{dynamicBlogName}/post/{dynamicPostName}",            
      new { controller = "PostController", action = "Default", dynamicBlogName = "", dynamicPostName=""  }
);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文