7

我的项目是在 MVC3 Razor Tech 中开发的。我的母版页和内容页是使用 Razor MVC3 开发的。我想在我的项目中显示一个 SSRS 报告生成器。我在博客中搜索并得知我们无法在 MVC3 Razor 中显示 SSRS 报告。由于我们可以'webform'在 MVC3 中使用,我们可以显示报告。

问题:在我的项目中,母版页和内容页都是用 Razor 开发的,.cshtml因为访问.aspx很困难。如果我错了,请纠正我。

要求:请帮助我在'VIEW'MVC3 Razor 框架中显示网络表单。即我的项目登录页面是webform. 在该网页表单页面中,我需要显示 SSRS 报告

4

3 回答 3

10

我必须这样做,所以我为我工作:

假设您有一个名为Summary的控制器。对于此实施,您无需添加或修改您拥有的任何操作。

然后,正如您告诉我的,您在视图文件夹中添加一个名为“SkillReport.aspx”的文件

 Views/Summary/SkillReport.aspx

(最初留在空白 SkillReport.aspx 或只是添加一些文本,如“技能报告”)

在 Global.asax 中:

    public static void RegisterRoutes(RouteCollection routes)
    {
       routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

       routes.MapPageRoute("Report", "Report/{rptController}/{rptName}", "~/Views/{rptController}/{rptName}.aspx");
       ...
    }

****--> 我附上了我的解决方案资源管理器的快照 enter image description here 我的 routes.Mappageroute 代码是 " routes.MapPageRoute("Report", "Report/Summary", "~/Views/Summary/SkillReport.aspx"); " 请更改上述文件夹结构的 mapPageRoute。** <--

The values ​​enclosed in {} are placeholders. You must not give the name of the controller or report there. When a request is received, this route determines which controller to invoke by adding the suffix "rptController" to the controller value in the URL to determine the type name of the controller that will handle the request. The rptName value in the URL determines which WebForm.aspx to call.

Suppose you need other two reports.

  1. In Summary controller, and report name FullNames
  2. In a controller named Product, and report name List.

Using the parameters you avoid having to create a route for each report.

routes.MapPageRoute("Report", "Report/{rptController}/{rptName}", "~/Views/{rptController}/{rptName}.aspx");


http://localhost/Report/Summary/SkillReport  --> /Views/Summary/SkillReport.aspx
http://localhost/Report/Summary/FullNames    --> /Views/Summary/FullNames.aspx
http://localhost/Report/Product/List         --> /Views/Product/List.aspx

On this route we added:

  1. "Report" is the name of this route, you can put any other

  2. "Report/{rptController}/{rptName}" : This is the pattern URL to identify when to invoke your Report-WebForm, "Report" works as "key" and {rptController} is the name of the controller. rptController will be assigned with the Controller name. In this case Summary and rptName with SkillReport

  3. "~/Views/{rptController}/{rptName}.aspx" is the physical path. When using this route with Summary controller, and call SkillReport this will invoke to Views/Summary/SkillReport.aspx

Routing documentation: http://msdn.microsoft.com/en-us/library/cc668201(v=vs.100).aspx#url_patterns

At this point you can verify that you can access your SkillReport.aspx in your development environment using :

http://localhost/Report/Summary/SkillReport  

Or maybe at some particular port... like

http://localhost:1057/Report/Summary/SkillReport  

Finally, SkillReport.aspx (like this... check ProcessingMode...)

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SkillReport.aspx.cs" Inherits="XXX.SkillReport" %>

    <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>



    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <meta http-equiv="X-UA-Compatible" content="IE=100"/>
    </head>
    <body>
        <form id="frmRpt" runat="server">
        <div>
            <asp:ScriptManager ID="sm" runat="server">
            </asp:ScriptManager>
            <rsweb:ReportViewer ID="rpt" runat="server" Width="100%" Height="90%" AsyncRendering="false" ProcessingMode="Local" ShowRefreshButton="false">
            </rsweb:ReportViewer>
        </div>
        </form>
    </body>
    </html>    

With this tag

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >

you achieve that show in Safari and other browsers.

To access the report from a VIEW (.cshtml) need to add a link. i. e. :

<a href="/Report/Summary/SkillReport" >Show My Report :) </a>  

As a last comment, I recommend that after creating SkillReport.aspx enter in "Design Mode" and drag from the toolbox the Reporting's controls. This will automatically register the required values ​​in web.config

于 2013-01-05T12:03:58.913 回答
3

Answer #1 was useful:

Just make sure that your order of MapRoutes is in the right order of precedence:

e.g.:

 public static void RegisterRoutes(RouteCollection routes)
 {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

           routes.MapPageRoute(
           routeName: "Report/", 
           routeUrl: "Report/{rptController}/{rptName}", 
           physicalFile: "~/Views/{rptController}/{rptName}.aspx"
       );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
}
于 2014-04-03T23:34:28.623 回答
1

虽然这不是推荐的做法,但它是可行的。我正在复制一个链接,该链接向您展示如何在同一个项目中使用两个视图引擎。

http://weblogs.asp.net/gunnarpeipman/archive/2010/07/29/asp-net-mvc-3-using-multiple-view-engines-in-same-project.aspx

让我知道这是否适合您。

更新: 这也可能有帮助,另一个选项看起来像为您的 aspx 页面注册路由。

[StackOverflow 帖子] MVC3 中的 Aspx 页面

于 2013-01-05T11:57:19.647 回答