【发布时间】:2012-01-07 07:30:51
【问题描述】:
我在 global.asax 中配置了这样的路线
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"poems-by-profile", // Route name
"profile/{id}/{name}/poems", // URL with parameters
new { controller = "poems", action = "Index", id = "", name = "" } // Parameter defaults
);
routes.MapRoute(
"profile", // Route name
"profile/{id}/{name}", // URL with parameters
new { controller = "profile", action = "Index", id = "", name = "" } // Parameter defaults
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/{name}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional, name = UrlParameter.Optional } // Parameter defaults
);
这是我的两个控制器
public class ProfileController : BaseController
{
public ActionResult Index(int id, string name)
{
return View();
}
}
public class PoemsController : BaseController
{
public ActionResult Index(int id, string name)
{
return View();
}
}
在主页的某个地方,我有这样的 html 操作链接
@Html.ActionLink("Profile", "index", "Profile", new { id = 1, name = "someuser" })
@Html.ActionLink("Poems by ", "index", "poems", new { id = 1, name = "someuser" })
我期待两个像
这样的网址http://localhost/profile/1/someuser
http://localhost/profile/1/someuser/poems
但它不会创建这些 url。
我是不是做错了什么。
我们将不胜感激。
//在这里更新我的问题
其实这个是可行的
@Html.ActionLink("Profile", "index", "Profile", new { id = 1, name = "someuser" },null)
@Html.ActionLink("Poems by ", "index", "poems", new { id = 1, name = "some user" },null)
将 null 作为最后一个参数传递。
不知道为什么,但它有效。
干杯
帕米德
【问题讨论】:
-
你实际生成的链接是什么?
-
@Floradu88 它正在生成主页链接 (localhost)
标签: c# asp.net-mvc asp.net-mvc-3 routes