I've got a section Left
that contains navigation content for my specific page.
Now I want to display a TreeView in that, thus I created a partial view to pass a specific model to that view. Now I'm trying to render that specific view into my section - but the section stays empty.
This does not work:
@section Left {
@Html.Partial("PartialNavigationView")
}
And rendering the thing returns an error Expression must return a value to render
:
@section Left {
@Html.RenderPartial("PartialNavigationView")
}
How can I render a partial view into my section?
Rendering a Partial View You can render the partial view in the parent view using the HTML helper methods: @html. Partial() , @html. RenderPartial() , and @html. RenderAction() .
Declare partial viewscshtml markup file without an @page directive maintained within the Views folder (MVC) or Pages folder (Razor Pages). In ASP.NET Core MVC, a controller's ViewResult is capable of returning either a view or a partial view.
To create a partial view, right-click on view -> shared folder and select Add -> View option. In this way we can add a partial view.
Try
@{Html.RenderPartial("PartialNavigationView");}
or
@{Html.Partial("PartialNavigationView");}
should work also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With