MVC 路由不拾取查询字符串
在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VS 2008 或框架似乎出了问题。现在运行良好。感谢您的关注。
Seems like something's acting up on VS 2008 or with the framework. It's working nicely now. Thanks for looking.