How to add partial views in in a view in an orchardcore theme

376 Views Asked by At

I converted layout.liquid to layout.csthml so I can see the syntax highlighting.

Then, how do I add partial views inside a view (layout.cshtml) in an OrchardCore theme?

I tried to call it

    <partial name="~/TheExperimentalTheme/Views/_MyPartial.cshtml" />

    <partial name="_MyPartial.cshtml" />

But no partial gets rendered.

The location of the partial view is inside another project - The theme

enter image description here

But what is rendered in page source is only

    <partial name="/TheExperimentalTheme/Views/_MyPartial.cshtml" />

The whole layout page is rendered so no error that says my partial is not found.

I tried to call

    @await Html.PartialAsync("_MyPartial") 

and not the partial tag helper and I got this error

An unhandled exception occurred while processing the request. InvalidOperationException: The partial view '_MyPartial' was not found. The following locations were searched: /Areas/OrchardCore.Cms.Web/Views/TheTheme/Home/_MyPartial.cshtml /Areas/OrchardCore.Cms.Web/Views/TheTheme/Shared/_MyPartial.cshtml /Areas/OrchardCore.Cms.Web/Views/Shared/_MyPartial.cshtml /Areas/TheExperimentalTheme/Views/TheTheme/Home/_MyPartial.cshtml /Areas/TheExperimentalTheme/Views/TheTheme/Shared/_MyPartial.cshtml /Areas/TheExperimentalTheme/Views/Shared/_MyPartial.cshtml /Areas/OrchardCore.Roles/Views/Shared/_MyPartial.cshtml /Areas/OrchardCore.Settings/Views/Shared/_MyPartial.cshtml /Areas/TheTheme/Views/Home/_MyPartial.en-PH.cshtml /Areas/TheTheme/Views/Home/_MyPartial.en.cshtml /Areas/TheTheme/Views/Home/_MyPartial.cshtml /Areas/TheTheme/Views/Shared/_MyPartial.en-PH.cshtml /Areas/TheTheme/Views/Shared/_MyPartial.en.cshtml /Areas/TheTheme/Views/Shared/_MyPartial.cshtml /Views/Shared/_MyPartial.en-PH.cshtml /Views/Shared/_MyPartial.en.cshtml /Views/Shared/_MyPartial.cshtml /Pages/Shared/_MyPartial.en-PH.cshtml /Pages/Shared/_MyPartial.en.cshtml /Pages/Shared/_MyPartial.cshtml

Microsoft.AspNetCore.Mvc.ViewFeatures.HtmlHelper.RenderPartialCoreAsync(string partialViewName, object model, ViewDataDictionary viewData, TextWriter writer)

1

There are 1 best solutions below

0
On

I placed it under the Shared folder in my theme project.