html.actionlink未创建正确的链接
本文关键字:链接 创建 actionlink html | 更新日期: 2023-09-27 18:19:45
我在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" })
我期待两个类似的URL
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作为最后一个参数传递。
不知道为什么,但它是有效的。
干杯
Parminder
尝试
@Html.ActionLink("Profile", "index", new {controller="Profile" id = 1, name = "someuser" })