Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render Partial in WebPages without using MVC

I'm using Razor with WebPages but without MVC. I like the simplicity with this so I'm not interested in using MVC at this point. However I would like to be able to render a partial into my page. Like a menu, a footer, etc.

With MVC you can to this: @{ Html.RenderPartial("Footer", Model);}

I would like to do something similar: @{ Html.RenderPartial("footer.cshtml"); }

How can I achieve what I want?

like image 495
Adrian Rosca Avatar asked Mar 27 '13 08:03

Adrian Rosca


People also ask

Which method is used to render partials?

RenderPartial(HtmlHelper, String, Object, ViewDataDictionary) Renders the specified partial view, replacing the partial view's ViewData property with the specified ViewDataDictionary object and setting the Model property of the view data to the specified model.

How do I render a partial view inside?

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.


1 Answers

take a look at this link http://www.mikesdotnetting.com/Article/151/Extending-ASP.NET-Web-Pages-Create-Your-Own-Helpers

Hope this will help you

also try this:

<!DOCTYPE html>
<html>
  <head>
    <title>Main Page</title>
  </head>
  <body>
    @RenderPage("/Shared/_Header.cshtml")
    <h1>Index Page Content</h1>
    <p>This is the content of the main page.</p>
    @RenderPage("/Shared/_Footer.cshtml")
  </body>
</html>
like image 167
Yosra Galal Avatar answered Nov 15 '22 06:11

Yosra Galal