繁体   English   中英

asp.net MVC3自定义路由的Doddle报告

[英]asp.net MVC3 custom route for Doddle Report

我正在使用Doodle报告,该报告以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时会输出以下URL 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" }

但这输出URL localhost/Report/ReadMeters.htm?id=19

这不起作用,并且出现以下错误:

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

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

有任何想法如何解决这个问题吗? 这是我的第一个MVC项目,到目前为止,该项目的其他区域都依赖于默认的路由机制,但仍受此限制。

感谢您的帮助,谢谢

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

希望该项目对您有所帮助!

你可以做这样的事情...

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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM