How do I render a full fledged view (not partial view) inside another view?
Scenario, I have different controller and want the exactly same view to render which is already there under other controller with different layout.
I have Wishlist page in Home Controller which shows list of added products, and when user logged in , when I click on wish list it also show me navigation when user is signed in.
How would I do that??
Partial function which renders the Partial View. The name of the View and the object of the CustomerModel class are passed to the @Html. Partial function. In order to add Partial View, you will need to Right Click inside the Controller class and click on the Add View option in order to create a View for the Controller.
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. It is not mandatory to create a partial view in a shared folder but a partial view is mostly used as a reusable component, it is a good practice to put it in the "shared" folder.
Not many developers know about this but you can use RenderPage, it's specifically designed for that purpose(to render an MVC view inside another view)
@RenderPage("~/Views/Shared/SampleView.cshtml")
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