MVC路由不会拾取查询字符串

时间:2009-10-15 16:36:09

标签: asp.net-mvc asp.net-mvc-routing query-string

在我的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

非常感谢, 肯尼。

1 个答案:

答案 0 :(得分:0)

看起来像VS 2008或框架上的某些东西。它现在很好用。谢谢你的期待。