ASP.NET MVC2 路由映射忽略操作和 id
我正在尝试向我正在开发的网站添加常见问题解答部分,并且我想忽略添加到 URL 的任何操作或 ID。
Global.asax.cs 文件的 RegisterRoutes 方法已更改为;
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"FAQ",
"FAQ",
new {controller = "FAQ", action= "Index"});
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
FAQController.cs 看起来像这样;
public class FAQController : Controller
{
private FAQModel _faq = new FAQModel();
public ActionResult Index()
{
return View(_faq.GetFAQ());
}
}
但这似乎不起作用,我想知道是否有人可以指出我如何做到这一点的正确方向。
感谢萨塔尔提前提供的任何帮助
:)
I'm trying to add a FAQ section to a website that I'm working on and I want to ignore any action or id that is added to the URL.
The RegisterRoutes method of the Global.asax.cs file has been changed to;
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"FAQ",
"FAQ",
new {controller = "FAQ", action= "Index"});
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
The FAQController.cs looks like this;
public class FAQController : Controller
{
private FAQModel _faq = new FAQModel();
public ActionResult Index()
{
return View(_faq.GetFAQ());
}
}
But this doesn't appear to be working, I was wondering whether anyone could point me in the right direction of how to do this.
Thanks for any help in advance
Satal :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: