Asp.net mvc MVC路由没有';t形拾音器
在my Global.ascx.cs中,我有以下路由设置:Asp.net mvc MVC路由没有';t形拾音器,asp.net-mvc,asp.net-mvc-routing,query-string,Asp.net Mvc,Asp.net Mvc Routing,Query String,在my Global.ascx.cs中,我有以下路由设置: routes.MapRoute( "HomeTarget", "{TargetCode}", new { controller = "Home", action = "Index", TargetCode = "" }); routes.MapRoute( "Default", // Route name "{controller
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”作为目标代码,但它没有。。。我应该怎么做才能将“Test1”作为TargetCode提取,我不想这样做:mysite.com/?TargetCode=Test1
多谢各位,
肯尼。似乎VS2008或框架出现了问题。它现在运行得很好。感谢您的关注。您的示例在一个简单的ASP.NET MVC应用程序中工作,该应用程序使用默认的Visual Studio模板创建,并在Cassini下运行。因此,也许在您的配置中有一些特定的东西阻止它选择所需的路线。显然MVC引擎或VS。。。我只是注释掉了代码,构建了解决方案,然后取消了对代码的注释,然后重新构建,一切都按照预期工作!谢谢你找达林。