I am working on a MVC3 Razor web application that gets page decoration from java content management system. Since this decoration is shared by every page, I put the extraction of the CMS content in the _Layout.cshtml file, but I'm not quite happy with the code I implemented ...
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> @{ -- The first two lines are temporary and will be removed soon. var identity = new GenericIdentity("", "", true); var principal = new GenericPrincipal(identity, new string[] { }); var cmsInterface = MvcApplication.WindsorContainer.Resolve<ICMSInterface>(); cmsInterface.LoadContent(principal, 2); } @Html.Raw(cmsInterface.GetHeadSection()) </head> <body> @Html.Raw(cmsInterface.GetBodySection(0)) @RenderBody() @Html.Raw(cmsInterface.GetBodySection(1)) </body> </html>
Since there is no controller for the _layout file, I do not see where else I could put the code to extract. Here are a few things I looked at:
- Extract the contents of the CMS in separate parts, so I don’t need to call LoadContent. Unfortunately, due to the component that I have to use to extract the contents of the CMS, this is not possible, is it all or nothing.
- Use a partial view so that I can use the controller. Since I would need to translate the entire page into a partial one, this option seems a bit ridiculous.
- Calling one static method for some helper class that retrieves data and adds three sections to the ViewBag. This will allow me to get the code out of the view and feel like a better solution, but I'm still not very happy with it.
Does anyone have any other suggestions / comments?
source share