MVC路由问题——url生成
我要创建一个看起来像 website.com/sea/season/23/team 的 url
这是 MapRoute
routes.MapRoute(
"SeaTeam",
"sea/season/{seasonId}/team/{action}/{name}",
new { controller = "Team", action = "Index", name = UrlParameter.Optional }
);
Html.ActionLink 看起来像
@Html.ActionLink("Add Team", "Index", "SeaTeam", new { seasonId = seasons.id }, null)
但它生成以下 url
<a href="/SeaTeam?seasonId=1">Add Team</a>
有什么见解吗?谢谢...
更新
这是控制器
public class TeamController : Controller
{
//
// GET: /Team/
public ActionResult Index()
{
//get the seasons of the loged user
var loadedTeam = tempFunctions.getSeasonsOf(CustomHelper.UserGuid(User.Identity.Name));
return View("Team/ManageTeam", loadedTeam);
}
I what to create a url that looks like website.com/sea/season/23/team
Here is the MapRoute
routes.MapRoute(
"SeaTeam",
"sea/season/{seasonId}/team/{action}/{name}",
new { controller = "Team", action = "Index", name = UrlParameter.Optional }
);
The Html.ActionLink looks like
@Html.ActionLink("Add Team", "Index", "SeaTeam", new { seasonId = seasons.id }, null)
But its generating the following url
<a href="/SeaTeam?seasonId=1">Add Team</a>
Any insights? Thanks...
Update
Here is the controller
public class TeamController : Controller
{
//
// GET: /Team/
public ActionResult Index()
{
//get the seasons of the loged user
var loadedTeam = tempFunctions.getSeasonsOf(CustomHelper.UserGuid(User.Identity.Name));
return View("Team/ManageTeam", loadedTeam);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
我没有看到
SeaTeam
控制器try:
I don't see a
SeaTeam
Controller