soundaranbu/Razor.Templating.Core

Layout page gets loaded with the partial view

flgatormike opened this issue · 2 comments

When I calll RazorTemplateEngine.RenderAsync, the string that is returned includes my layout page. I'm wondering if this is by design, and if so, how can I specify a different layout page to use?

Hi @flgatormike , the razor rendering works the same way as the ASP.NET Core MVC.
In your case, if you have ~/Views/_ViewStart.cshtml in your project like below

@{
    Layout = "_Layout";
}

then, the partial view or view will inherit this layout file when you render it directly.

In order to overcome this, either remove the ~/Views/_ViewStart.cshtml file or add the following in your partial view or view file

@{ 
    Layout = null;
}

some helpful links: https://stackoverflow.com/questions/6613626/razor-view-without-layout

I hope the above information is helpful. Closing the issue. Feel free to re-open if required.