4
我想收到一个字符串作为URL中的ID。这里是一个例子:URL路由:如何将字符串作为我的ID?
http://www.example.com/Home/Portal/Fishing
我想在我的ID钓鱼。
从Global.asax.cs中public ActionResult Portal(string name)
{
// some code
ViewData["Portal Name"] = name;
}
代码:从我的控制器
代码:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
非常感谢。有用! – GabrielC