MVC 路由不拾取查询字符串

发布于 2024-08-08 02:25:37 字数 776 浏览 7 评论 0原文

在我的 Global.ascx.cs 中,我有这样的路由设置:

routes.MapRoute(
"HomeTarget",
"{TargetCode}",
new { controller = "Home", action = "Index", TargetCode = "" });

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults

在我的 HomeController 中,我有一个像这样的 Index() 操作:

[AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Index(string TargetCode)
    {
        return View();
    }

当我访问该站点时,例如 mysite.com/Test1,我想它应该将“Test1”作为 TargetCode,但它没有...我该怎么做才能将“Test1”作为 TargetCode,我不想这样做:mysite.com/?TargetCode=Test1

谢谢非常, 肯尼.

in my Global.ascx.cs, I have this setting for the routing:

routes.MapRoute(
"HomeTarget",
"{TargetCode}",
new { controller = "Home", action = "Index", TargetCode = "" });

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults

In my HomeController, I have an Index() action like this:

[AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Index(string TargetCode)
    {
        return View();
    }

When I go to the site, for example, mysite.com/Test1, I suppose it should take "Test1" as the TargetCode, but it didn't... What should I do for it to pickup the "Test1" as TargetCode, I don't want to do this: mysite.com/?TargetCode=Test1

Thank you very much,
Kenny.

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

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

发布评论

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

评论(1

紫罗兰の梦幻 2024-08-15 02:25:37

VS 2008 或框架似乎出了问题。现在运行良好。感谢您的关注。

Seems like something's acting up on VS 2008 or with the framework. It's working nicely now. Thanks for looking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文