English 中文(简体)
国家安全局的意见 ASP.net MVC的报告 地点
原标题:Viewing SSRS Reports in an ASP.net MVC Site

是否有办法将服务器报告服务供应商控制放在协会的网络MVC观点上? 如果不是......做到这一点的最佳途径是什么?

最佳回答

No, not in a MVC view. 但你可以有一个网页,其服务器控制与MVC网站混合。

Hmm, just googled "mix asp.net mvc and web forms" to find some examples, and google questioned whether I m human or not :)

任何方面,此处的链接—— - 其中有一些。 出于同样的原因,我也这样做了,即报告控制。

问题回答

执行SSRS 5. 监控监中心的工作包括两个问题:

  1. Minimally, you ll need to add the right dependencies, handlers, and configuration for the ReportViewer control (regardless of project type).
  2. The trickier hurdle is in Mixing WebForms and MVC. We need a way of rendering and routing incoming requests so they will be handled by WebForms pages, controls, and actions.

Problem 1 - Configuring the ReportViewer

如果你过去在建立举报人控制方面做了大量工作,这可能是老的,你可以跳到第2节。

  1. ReportViewer control life in the 微软,ReportViewer.WebForms.dll 。 可在贵项目中增加Microsoft.ReportViewer.WebForms。 a. 植被:

    “Nuget

  2. Web.config Handlers - Per this article on , and

    <system.web>
      <httpHandlers>
        <add verb="*" path="Reserved.ReportViewerWebControl.axd" 
             type="Microsoft.Reporting.WebForms.HttpHandler,
                   Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral,
                   PublicKeyToken=b03f5f7f11d50a3a" />
      </httpHandlers>
    </system.web>
    <system.webServer>
      <handlers>
        <remove name="ReportViewerWebControlHandler" />
        <add name="ReportViewerWebControlHandler" preCondition="integratedMode"
             verb="*" path="Reserved.ReportViewerWebControl.axd" 
             type="Microsoft.Reporting.WebForms.HttpHandler, 
                   Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral,
                   PublicKeyToken=b03f5f7f11d50a3a"/>
      </handlers>
    </system.webServer>
    

    Per

  3. www.un.org/Depts/DGACM/index_spanish.htm 图六 图像要求 - 报告中有明显缺陷,有blank.gif 不含的图像 您可在<全球编码>上添加以下案文:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        HttpRequest req = HttpContext.Current.Request;
        if (req.Url.PathAndQuery.StartsWith("/Reserved.ReportViewerWebControl.axd") &&
            !req.Url.ToString().ToLower().Contains("iteration") &&
            !String.IsNullOrEmpty(req.QueryString["ResourceStreamID"]) &&
            req.QueryString["ResourceStreamID"].ToLower().Equals("blank.gif"))
        {
            Context.RewritePath(String.Concat(req.Url.PathAndQuery, "&IterationId=0"));
        }
    }
    
  4. IgnoreRoute .axd - 如果尚未做到,确保 文本Resources ,载于RouteConfig.cs:

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
  5. Add ReportViewerPage.aspx - Add a WebForm page that will hold an instance of the ReportViewer control. In order to work, that control needs to find a ScriptManager control and be placed inside of a <form runat="server" >.
    So your new .aspx page should look something like this:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewerPage.aspx.cs" Inherits="MVCAppWithReportViewer.ReportViewerPage" %>
    <%@ Register TagPrefix="rsweb" Namespace="Microsoft.Reporting.WebForms" Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>
    
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Report Viewer</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <rsweb:ReportViewer ID="ReportViewer" runat="server" 
                                Height="100%" Width="100%" 
                                SizeToReportContent="True" ProcessingMode="Remote" />
            <asp:ScriptManager ID="ScriptManager1" runat="server" />
        </form>
    </body>
    </html>
    
  6. www.un.org/Depts/DGACM/index_spanish.htm 关于<代码>Page_Load的电线报告——假设你已经向一个报告服务器全面部署了SSRS报告,可在以下地址查阅:

    ReportServerName/Reports/Pages/Report.aspx?ItemPath=%2fCompany%2fClientReport>

    Then your code-behind in your new WebForm page should look like this:

    public partial class ReportViewerPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // confirm report properties (also setable in attributes)
                ReportViewer.ProcessingMode = ProcessingMode.Remote;
    
                // config variables
                var reportServer = "ReportServerName";
                var reportPath = "/Company/";
                var reportName = "ClientReport";    
    
                // report setup
                var serverReport = new ServerReport();
                serverReport = ReportViewer.ServerReport;
                serverReport.ReportServerUrl = new Uri($@"http://{reportServer}/ReportServer");
                serverReport.ReportPath = $@"{reportPath}{reportName}";
    
                // report input
                var parameters = new List<ReportParameter>();
                parameters.Add(new ReportParameter("User_uid", "1"));
                serverReport.SetParameters(parameters);
    
                // run report
                serverReport.Refresh();
            }
        }
    }
    
  7. http://www.ohchr.org。 此时此刻,你应能够自行阅读你的报告,选择。 参看Browser ;Ctrl+

    “Browser”/

Problem 2 - Mixing WebForms and MVC

首先,让我们迅速消除这些管制的装载方式与随后更新之间的路线差异。

这严重限制了我们现有的解决办法。 对<代码>ReportViewer的控制无任何例外。 它只是一组精练的用户群,通过将目前地址与“观点国家”和“事件”信息放在后面,对点击和其他投入活动作出反应。 因此,无论对报告撰写人行驶路线和航行有何假设,都必须坚持到我们的MVC包裹中去。

  1. Option 1 - Add Line for .aspx page

    如MVC 4.0+,可使用。 加上 编码Route/code>/code>, 页: 1 LineConfig.cs:

    routes.MapPageRoute(
        routeName: "ReportViewer",
        routeUrl: "ReportViewer/{reportName}",
        physicalFile: "~/ReportViewerPage.aspx"
    );
    

    报告将在你浏览<代码>~/Reports/reportName时进行。 这可能是从控制器行动中援引的,或许有些用户进入参数或网络。 ways to management state in ASP.NET and Pass Values to ASP. NET Web Forms pagess。 一种选择是将信息推向会议,并将这种信息转作你的控制人:

    HttpContext.Session[reportSetup.ReportName] = new ReportSetup() {ReportName = "ClientReport"}; //reportSetup;}
    return RedirectToRoute("ReportViewer", new { reportName = reportSetup.ReportName});
    

    接着,在.aspx页内,你可以从“公路价值”和届会的任何固定参数中选取reportName:

    // get report name from route
    string reportName = Page.RouteData.Values["reportName"].ToString();
    
    // get model from session and clear
    ReportSetup setup = (ReportSetup)HttpContext.Current.Session[reportName];
    

    <>Pros:

    • Most of the routing seems to work by default, and AJAX controls work fine, so you can set AyncRendering=True

    <>Cons:

    • It s hard to use an ASP Web Form with a Razor MVC Layout so rendering will take users out of the flow of the rest of the application.
    • Also, report values have to be exposed as part of the URL or passed indirectly via session (as opposed to hydrating directly onto the object).
  2. http://www.un.org/Depts/DGACM/index_spanish.htm 参看。

    改编自,但我能与Razor一起使用报告电文控制吗?。 部分控制 意见只要从>>>。

    创建新的网络用户控制系统,名称为ReportViewerControl.ascx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ReportViewerControl.ascx.cs" Inherits="MVCAppWithReportViewer.ReportViewerControl" %>
    <%@ Register TagPrefix="rsweb" Namespace="Microsoft.Reporting.WebForms" Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" %>
    
    <form id="form1" runat="server">
        <rsweb:ReportViewer ID="ReportViewer" runat="server" 
                            Height="100%" Width="100%"  
                            SizeToReportContent="True" ProcessingMode="Remote"
                            AsyncRendering="False" />
        <asp:ScriptManager ID="ScriptManager1" runat="server" 
                           EnablePartialRendering="false"  />
    </form>
    

    <<>strong>>>: 您必须建立<><> > 编码>>和<>strong><>>>> > > > > > > > > >。

    在你背后的法典中,需要将继承类型从<代码>System.Web.UI.UserControl改为System.Web.Mvc.ViewUserControl

    Context.Handler to code>Page < so>。

    页: 1 ReportViewerControl.ascx.cs ::

    public partial class ReportViewerControl : System.Web.Mvc.ViewUserControl
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            // Required for report events to be handled properly.
            Context.Handler = Page;
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                /* ... report setup ... */ 
                serverReport.Refresh();
            }
        }
    }
    

    为使报告提交,在你的控制者看来添加以下内容:

    @Html.Partial("ReportViewerControl", Model)
    

    然后,在《意见书》中。 页: 1 Load活动,请您从https://learn.microsoft.com/en-us/previous-versions/aspnet/web-framework/mt172252%28v%3dvs.118%29”rel=“nofollow noreferer”>ViewUserControl.Model <<><<><>>><>>>>>>>> 类似财产:

    ReportSetup setup = (ReportSetup)Model;
    

    <>Pros:

    • Can build into master _layout.cshtml and consume in regular views
    • Can pass model directly

    <>Cons:

<<>Further Reading

现在有一名MvcReportViewer助手。 我们可以从NuGet那里获得。

吉苏门特项目

NuGet Pack/a>

This is a bit simple and will require a bit of fixing to pass something decent to a view in MVC

public ActionResult Index()
{
    /*Credentials of a user that has access to SSRS*/
    string userid = "UserId";
    string password = "MyPassword";
    string domain = "MyDomain";

    string reportURL="http://ServerName/ReportServer?/ReportsFolder/ReportName&Parameter=UserName&rs:Command=Render&rs:Format=PDF";

    NetworkCredential nwc = new NetworkCredential(userid, password, domain);

    WebClient client = new WebClient();
    client.Credentials = nwc;

    Byte[] pageData = client.DownloadData(reportURL);

    Response.ContentType = "application/pdf";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + DateTime.Now);
    Response.BinaryWrite(pageData);
    Response.Flush();
    Response.End();

    //return View();
    }

一种简单的解决办法是,在MVC的观点中增加一个框架,打开你希望从报告服务网络处获得的报告。 框架将与报告服务的各个组成部分充分运作。 如果你想把部件移入MVC的视野,则对机体中的旋转参数(例如,与Ajax)进行动态控制。

虽然这项工作已经进行,但你仍须在网络报告服务处上签字(iframe将开设一个记录仪。 对电子电子计算机来说,这是通过使用你的窗口记录证书进行的“例行”工作。

可以通过使用Nuget在MVC安装报告器。

Install-Package Microsoft.Report.Viewer -Version 11.0.0

Install-Package Microsoft.ReportViewer.Runtime.WebForms -Version 12.0.2402.15

Install-Package ReportViewerForMvc

如上所示,一旦你安装了《报告意见书》和其他所需Nuget书,就在你的视觉演播室项目中添加了新的报告。

“entergraph

Add dataset in the above created report.rdlc

现在,在MVC设立一个行动措施,将查询数据库的数据和返回报告。

 SSRSInMVC.Report.Report ds = new SSRSInMVC.Report.Report();
    public ActionResult ReportStudent()
    {
        ReportViewer reportViewer = new ReportViewer();
        reportViewer.ProcessingMode = ProcessingMode.Local;
        reportViewer.SizeToReportContent = true;
        reportViewer.Width = Unit.Percentage(900);
        reportViewer.Height = Unit.Percentage(900);

        var connectionString = ConfigurationManager.ConnectionStrings["SSRSInMVC.Properties.Settings.StudentsConnectionString"].ConnectionString;


        SqlConnection conx = new SqlConnection(connectionString);
        SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM Student_details", conx);

        adp.Fill(ds, ds.Student_details.TableName);

        reportViewer.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + @"ReportReport1.rdlc";
        reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", ds.Tables[0]));


        ViewBag.ReportViewer = reportViewer;

        return View();
    }

您认为,其法典如下:

@using ReportViewerForMvc;
@{
   ViewBag.Title = "Report Student";
 }
 <br/>
<br />

   @Html.ReportViewer(ViewBag.ReportViewer as Microsoft.Reporting.WebForms.ReportViewer)

我们这样做了。

Reference: https://qawithexperts.com/article/asp.net/displaying-ssrs-sql-server-reporting-service-in-mvc-view/77

我面临许多问题,即把rs子的报告编成正文。 希望这一解决办法有助于。 i m 采用手法作为方案规划语言。

<>说明: 正在建立服务器报告服务器。 消耗器报告已在远程服务器上公布。

  1. Installing reportviewer package on to your solution. I m making use of nuget package manager console for setting up the dependent files required for the solution. I have installed ReportViewerForMvc14 for my solution and i m using .net framework 4.7.2 (as shown in the screenshot below)

<>说明: Install-Package ReportViewerForMVC don t work. I has included 14 at the end .

Go to Tool-> Nuget Pack Manager -> Pack Manager Console-> Selected the Object Project --> Ron the direct Install-Package ReportViewerForMvc14 .

“enter像

  1. 以上指挥将加上解决方案所需的佐证文件。 此外,在安装了“ForMvc”号检查报告之后,在参考文献中添加了该词。

  2. 在控制器中加入以下代码。 在确定了报告浏览器的所有特性之后,将报告浏览器内容储存起来。

    
    Function Index() As ActionResult
         Fetch ssrs report server url and case history folder path entries from config.
        Dim ssrsReportServerUrl As String = ConfigurationManager.AppSettings.Get("SSRSReportURL") 
        Dim caseHistoryFolderPath As String = ConfigurationManager.AppSettings.Get("SSRSCaseHistoryReportPath")
        Dim qsCaseId As String = "CaseID"
        Dim CaseId As Integer = 0
        If String.IsNullOrWhiteSpace(Request.QueryString(qsCaseId)) Then
            Throw New ArgumentNullException("Page did not receive Case Id parameter.")
        End If
        If Not String.IsNullOrWhiteSpace(Request.QueryString(qsCaseId)) Then
            CaseId = Request.QueryString(qsCaseId).ToString
        End If

        If Not String.IsNullOrEmpty(ssrsReportServerUrl) AndAlso Not String.IsNullOrEmpty(caseHistoryFolderPath) Then
            Dim reportViewer As New ReportViewer
            reportViewer.ProcessingMode = ProcessingMode.Remote

             Assign the reportserver url And path
            reportViewer.ServerReport.ReportServerUrl = New Uri(ssrsReportServerUrl)
            reportViewer.ServerReport.ReportPath = caseHistoryFolderPath

             Assign the input parameters to report.--add multiple parameters below if you have multiple..i have only one parameter to pass.
             to show the input parameter textbox entry on the screen , set below property to true.
            Dim rptParameters As New Microsoft.Reporting.WebForms.ReportParameter
            Dim paramarr(0) As Microsoft.Reporting.WebForms.ReportParameter
            rptParameters = New Microsoft.Reporting.WebForms.ReportParameter("CaseID", CaseId, False)
            paramarr(0) = rptParameters
            reportViewer.ServerReport.SetParameters(paramarr)

             //Set the report properties (width, zoom, refresh, print controls)
            reportViewer.SizeToReportContent = True
            reportViewer.ZoomMode = ZoomMode.FullPage
            reportViewer.AsyncRendering = False
            reportViewer.ShowBackButton = False
            reportViewer.ShowRefreshButton = True
            reportViewer.ShowFindControls = True
            reportViewer.ShowPageNavigationControls = True
            reportViewer.ShowPrintButton = True

            reportViewer.ShowZoomControl = True

            reportViewer.ServerReport.Refresh()
            ViewBag.ReportViewer = reportViewer
        Else
            Throw New ArgumentNullException("Report Server URL or the Report Path is Invalid.")
        End If

        Return View(VIEW_FILE, ViewModel)
    End Function
  1. Include the below code snippet in the view section of your page. I m using vbhtml page . I m getting the reportviewer viewbag and displaying in the vbhtml page for display.
@Imports ReportViewerForMvc


@Code
    ViewData("Title") = "Details"

End Code

    html, body {
        margin: 0;
        padding: 0;       
    }
    .myreport{
        background-color:#fff;
    }

@If Not ViewBag.ReportViewer Is Nothing Then @ @Html.ReportViewer(TryCast(ViewBag.ReportViewer, Microsoft.Reporting.WebForms.ReportViewer), New With {.htmlAttributes = New With {.width = "100%", .height = "100%", .scrolling = "no"}})

End If





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...