rmehra76
rmehra76

Reputation: 414

Rendering an aspx page in razor view (cshtml)

I need to render a crystal report in a asp.net mvc application. Since mvc does not provide the support for reportviewer.I'm forced to redirect to an aspx page.However i'm losing the layout.cshtml menu in that redirect .

Is there anyway we can do show the partial view of aspx page on the same razor page , in the same window?

Iframe is one solution that I'm aware but do not want to use it as it is not a good practice to use iframes in modern apps.

Thanks.

Upvotes: 0

Views: 1732

Answers (1)

woodykiddy
woodykiddy

Reputation: 6455

Well, if iframe isn't a practical option for you, then you perhaps should consider creating a WebForms Master page specifically for your report page(s).

Then on that Master page, you can set its default PlaceHolder controls to invisible and explicitly render the Razor layout view within server tags.

<%   var buildTitle = new StringBuilder();
     var buildMain = new StringBuilder();
     TitleContent.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(buildTitle)));
     ViewBag.Title = buildTitle.ToString().Trim();
     MainContent.RenderControl(new HtmlTextWriter(new System.IO.StringWriter(buildMain)));
     ViewBag.MainContent = buildMain.ToString().Trim();
%>
<%= Html.Partial("YourRazorLayoutView", viewData: ViewData)%>

For more details, please go check out this blog.

Upvotes: 1

Related Questions