Search code examples
asp.netrazorrazor-2

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?


Solution

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