MVC路由问题——url生成

发布于 2024-10-09 10:34:52 字数 901 浏览 4 评论 0 原文

我要创建一个看起来像 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ繥欢鉨o。 2024-10-16 10:34:52

尝试:

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

我没有看到 SeaTeam 控制器

try:

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

I don't see a SeaTeam Controller

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文