Generating StiNetCoreViewer from the server and sending as s
Posted: Tue Oct 24, 2017 10:17 am
Hello,
I'm trying to generate StiNetCoreViewer, parse it to string and send it back to the client. Unfortunately I'm having a small issue and I do not know what I'm doing wrong here
The Index View:
Here is the simple action which should generate the view and send back as string
The exception is being thrown in Index.cshtml when intializing Html.Stimulsoft()... and it is being invoked
by await view.RenderAsync(viewContext);
The methods GetReport() and ViewerEvent() are also in the same controller but they are not being invoked at all
If I delete @Html.Stimulsoft().StiNetCoreViewer... from View, Hello World is being displayed properly
The exception which is being thrown:
It looks like Stimulsoft.Report.NetCore\Helpers\StiRequestParamsHelper.cs:line 200 requires some sort of list or sth but I can't find any documentation about that.
Can you be of any help?
Cheers
I'm trying to generate StiNetCoreViewer, parse it to string and send it back to the client. Unfortunately I'm having a small issue and I do not know what I'm doing wrong here
The Index View:
Code: Select all
@using Stimulsoft.Report.NetCore;
@{
ViewData["Title"] = "Home Page";
}
<br />
<p>hello world</p>
@Html.Stimulsoft().StiNetCoreViewer("NetCoreViewer1", new StiNetCoreViewerOptions()
{
Actions =
{
GetReportData = "GetReport",
ViewerEvent = "ViewerEvent"
}
})
The exception is being thrown in Index.cshtml when intializing Html.Stimulsoft()... and it is being invoked
by await view.RenderAsync(viewContext);
Code: Select all
private ActionContext GetActionContext(IServiceProvider serviceProvider)
{
var httpContext = new DefaultHttpContext
{
RequestServices = serviceProvider
};
return new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
}
[HttpGet]
public async Task<IActionResult> GetReportView(
[FromServices] IRazorViewEngine razorViewEngine,
[FromServices] IServiceProvider serviceProvider,
[FromServices] ITempDataProvider tempDataProvider)
{
var reportView = GetReportView(); // This method returns just a class with .Data property as generated report with byte[] type
ViewBag.Data = reportView.Data;
var name = "Index";
var actionContext = GetActionContext(serviceProvider);
var viewEngineResult = razorViewEngine.FindView(actionContext, name, false);
if (!viewEngineResult.Success)
{
throw new InvalidOperationException(string.Format("Couldn't find view '{0}'", name));
}
var view = viewEngineResult.View;
using (var output = new StringWriter())
{
var viewContext = new ViewContext(
actionContext,
view,
new ViewDataDictionary<TModel>(
metadataProvider: new EmptyModelMetadataProvider(),
modelState: new ModelStateDictionary())
{
Model = null
},
new TempDataDictionary(
actionContext.HttpContext,
tempDataProvider),
output,
new HtmlHelperOptions());
await view.RenderAsync(viewContext);
result = output.ToString();
}
var contentResult = new ContentResult
{
Content = result,
ContentType = "text/html"
};
return contentResult;
}
Code: Select all
public IActionResult GetReport()
{
IActionResult result = null;
try
{
result = StiNetCoreViewer.GetReportDataResult(this, ViewBag.Data);
}
catch(Exception ex)
{
var msg = ex.Message;
var data = ex.Data;
}
return result;
}
public IActionResult ViewerEvent()
{
IActionResult result = null;
try
{
result = StiNetCoreViewer.ViewerEventResult(this);
}
catch (Exception ex)
{
var msg = ex.Message;
var data = ex.Data;
}
return result;
}
The exception which is being thrown:
Code: Select all
[12:12:39 ERR] Unhandled ArgumentOutOfRangeException at WebApi.Controllers.ReportController.GetReportView (WebApi)
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRange_IndexException()
at System.Collections.Generic.List`1.get_Item(Int32 index)
at Stimulsoft.Report.NetCore.StiRequestParamsHelper.GetRequestUrl(ViewContext viewContext, String controller, Boolean relativeUrls, Boolean passQueryParams) in D:\Stimulsoft\Stimulsoft.Reports\Stimulsoft.Report.NetCore\Helpers\StiRequestParamsHelper.cs:line 200
at Stimulsoft.Report.NetCore.StiNetCoreViewer.Render() in D:\Stimulsoft\Stimulsoft.Reports\Stimulsoft.Report.NetCore\Viewer\StiNetCoreViewer.Render.cs:line 77
at AspNetCore._Views_Shared_Index_cshtml.<ExecuteAsync>d__0.MoveNext() in C:\backend-report-server\backend-report-server\ReportServer.WebApi\Views\Shared\Index.cshtml:line 7
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.<RenderPageCoreAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Razor.RazorView.<RenderPageAsync>d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Microsoft.AspNetCore.Mvc.Razor.RazorView.<RenderAsync>d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ReportServer.WebApi.Controllers.ReportController.<GetReportView>d__3.MoveNext() in C:\backend-report-server\backend-report-server\ReportServer.WebApi\Controllers\ReportController.cs:line 115
--- End of stack trace from previous location where exception was thrown ---
Can you be of any help?
Cheers