MVC路由问题 - url生成

时间:2010-12-30 15:21:11

标签: asp.net-mvc asp.net-mvc-routing asp.net-mvc-3

我要创建一个类似于website.com/sea/season/23/team

的网址

这是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)

但它生成以下网址

<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);
    }

1 个答案:

答案 0 :(得分:1)

尝试:

@Html.ActionLink(
    "Add Team", // linkText
    "Index", // Action
    "Team", // Controller
    new { seasonId = seasons.id }, 
    null)

我没有看到SeaTeam控制器