MVC routing doesn't pickup querystring

大憨熊 提交于 2020-01-06 08:21:12

问题


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:


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



来源:https://stackoverflow.com/questions/1573566/mvc-routing-doesnt-pickup-querystring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!