Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render a View inside a View in Asp.Net mvc

Tags:

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??

like image 949
trighati Avatar asked Sep 01 '16 10:09

trighati


People also ask

How do you render a partial view inside a view in MVC?

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.

How do I render a partial view in another view in 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. 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.


1 Answers

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") 
like image 139
Denys Wessels Avatar answered Oct 30 '22 14:10

Denys Wessels