Reputation: 18859
I've created functionality for my client to create dynamic pages. They create a page in the admin tool by specifying the Name and HTML for the page. Then, if someone on the front-end navigates to http://www.site.com/content/{Name}, the dynamic content is loaded.
Here's what I have. Global.asax:
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute(
"Content", // Route name
"Content/{name}", // URL with parameters
new { controller = "ContentPages", action = "Page" }
);
}
and ContentPagesController:
public ContentResult Page(string name)
{
var contentPage = _contentPagesRepository.GetContentPage(name);
return new ContentResult
{
Content = contentPage.Content,
ContentType = "text/html"
};
}
This works great. Everything loads correctly.
I also have other pages that aren't dynamic, like the Contact Us page. All these other pages use a Layout page. The problem is that the dynamic pages don't have the HTML from the Layout page.
Is there any way to load up the dynamic content, and somehow utilize the RenderBody()
function of the Layout page and wrap the content in the Layout HTML?
I'm using MVC 3 and Razor.
Upvotes: 0
Views: 576
Reputation: 14419
If you use MVC then your problem is solved. Load the page in the controller. Pass the page to a view. The view uses the layout.
Why are you not doing this?
That is how we do it and our pages can be different. You can store a view for each page type or create a view that works with your dynamic content. We have done both and both approaches work well. We actually use both approaches in the same project depending on the needs as both have strengths.
Upvotes: 1