ASP.NET MVC2 路由映射忽略操作和 id

发布于 2024-09-26 18:55:15 字数 850 浏览 1 评论 0原文

我正在尝试向我正在开发的网站添加常见问题解答部分,并且我想忽略添加到 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 技术交流群。

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

发布评论

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

评论(1

眸中客 2024-10-03 18:55:15

试试这个:

routes.MapRoute(
    "FAQ", 
    "FAQ/{*pathInfo}", 
    new { controller = "FAQ", action = "Index" }
);

Try this:

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