Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render PartialView into section

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?

like image 513
SeToY Avatar asked Aug 06 '13 13:08

SeToY


People also ask

How do I render a partial part of a view?

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() .

How do I render a partial view in dotnet core?

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.

How do you render a partial view in layout MVC 4?

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.


1 Answers

Try

@{Html.RenderPartial("PartialNavigationView");}

or

@{Html.Partial("PartialNavigationView");}

should work also.

like image 94
Jason Evans Avatar answered Oct 06 '22 03:10

Jason Evans