[英]html.actionlink not creating right links
我在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作为最后一个参数传递。
不知道为什么,但是它有效。
干杯
策划者
尝试
@Html.ActionLink("Profile", "index", new {controller="Profile" id = 1, name = "someuser" })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.