【问题标题】:routing in asp.net mvc gives me lenghtasp.net mvc 中的路由给了我长度
【发布时间】:2015-05-10 08:53:19
【问题描述】:

我正在尝试创建这条路线:

http://localhost:28790/Admin/Reporting/Reporting?reportName=MyReportName

为了访问这个控制器:

public ActionResult Reporting(string reportName){...}

为此,我在该区域添加了此路由:

context.MapRoute(
                "Admin_Reporting",
                "Admin/Reporting/Reporting/{reportName}",
                new
                {
                    reportName = UrlParameter.Optional
                }
            );

我已经测试了这个 ActionLink

@Html.ActionLink(My Link, "Reporting", "Reporting", new { area = "Admin", reportName = "reportingName" })

但结果确实不是我所期望的:

http://localhost:28790/Admin/Reporting/Reporting?Length=9

我该怎么做才能让正确的 URL(文章的第一个 URL)插入这个错误的 URL(文章的最新 URL)?

提前感谢您的帮助

【问题讨论】:

  • 您使用了错误的重载。必须是@Html.ActionLink(My Link, "Reporting", "Reporting", new { area = "Admin", reportName = "reportingName" }, null)null是html属性)
  • Arghhh 我知道我忘记了什么!谢啦!把它放在答案中,我会验证它!

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


【解决方案1】:

您使用了错误的 @Html.ActionLink() 重载。 html属性(最后一个参数)指定null时需要使用this overload

@Html.ActionLink("My Link", "Reporting", "Reporting", new { area = "Admin", reportName = "reportingName" }, null)

【讨论】:

    猜你喜欢
    • 2010-11-14
    • 2011-06-26
    • 1970-01-01
    • 1970-01-01
    • 2015-04-06
    • 2014-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多