This is my folder structure
I wan to call a partialview from my view on my area
To create a partial view, right click on the Shared folder -> click Add -> click View.. to open the Add View popup, as shown below. You can create a partial view in any View folder. However, it is recommended to create all your partial views in the Shared folder so that they can be used in multiple views.
A partial view is a Razor markup file ( . cshtml ) without an @page directive that renders HTML output within another markup file's rendered output. The term partial view is used when developing either an MVC app, where markup files are called views, or a Razor Pages app, where markup files are called pages.
cshtml before the rendering and also, partial view rendered within another view. Partial view is normally rendered in the main views using @Html. Partial() method. Partial view passes the name of the partial and also can pass a model data which is basically optional.
The primary difference between the two methods is that Partial generates the HTML from the View and returns it to the View to be incorporated into the page. RenderPartial, on the other hand, doesn't return anything and, instead, adds its HTML directly to the Response object's output.
You could specify the full location of the view when rendering it:
<% Html.RenderPartial("~/Areas/User/Views/SomeController/Foo.ascx"); %>
UPDATE:
And in order to call a partial from the Shared
folder:
<% Html.RenderPartial("~/Views/Shared/Foo.ascx"); %>
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