MVC routing doesn't pickup querystring

2019-09-10 02:17发布

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.

1条回答
smile是对你的礼貌
2楼-- · 2019-09-10 02:46

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

查看更多
登录 后发表回答