用于Doddle Report的asp.net MVC3自定义路由

时间:2011-09-23 08:15:04

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

我正在使用涂鸦报告,它以pds,html和xls格式输出快速报告。它工作正常,如下面的文档链接所示:

http://doddlereport.codeplex.com/wikipage?title=Web%20Reporting

现在我需要能够将ID值传递给控制器​​,以便动态生成报告。

默认路线如下:

     return routes.MapRoute("DoddleReport",
                "{controller}/{action}.{extension}",
                new { controller = defaultAction, action = defaultAction },
                new { extension = new ReportRouteConstraint() }

在使用以下

时输出以下网址localhost/Report/ReadMeters.htm
actionlink @Html.ActionLink("HTM", "ReadMeters", new{ extension = "htm"})

我试图在global.asax中添加一个新路由,它接受ID参数,如下所示:

 routes.MapRoute("DoddleReportExtension",
                "{controller}/{action}.{extension}/id",
                new { controller = "Report", action = "Index" },
                new { extension = new ReportRouteConstraint(),
                id = UrlParameter.Optional
                }
                );

并使用actionlink传递值:

@Html.ActionLink("View", "ReadMeters", new { id = ViewBag.ID, extension = "htm" }

但这是输出网址localhost/Report/ReadMeters.htm?id=19

这不起作用,我收到以下错误:

  “/”应用程序中的服务器错误   无法找到资源   说明:HTTP 404.您要查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。

     

请求的网址:/Report/ReadMeters.htm

任何想法如何解决这个问题?这是我的第一个MVC项目,到目前为止依赖于项目其他领域的默认路由机制,但却陷入了这个问题。

感谢您的帮助,谢谢

2 个答案:

答案 0 :(得分:2)

我知道我已经迟到了,但我是DoddleReport的作者,只是想说这个问题已经在最新的源码和NuGet包中解决了。它还支持MVC区域。

希望项目一直在帮助你!

答案 1 :(得分:1)

你可以这样做......

routes.MapRoute("DoddleReportExtension",
   "{Controller}/{Action}/{Extension}/{id}/",
    new { controller = Report, action = Index,Extension=new ReportRouteConstraint(), id=UrlParameter.Optional });

然后您可以将扩展名和ID发送到ActionResult ..

public ActionResult showItem(string Extension)
{
    //view stuff here.
}

public ActionResult showItem(string Extension, int id)
{
    //view stuff here
}
相关问题