Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:38:58+00:00 2026-05-31T17:38:58+00:00

I’m working on an MVC3 Razor web application which gets it’s page decoration from

  • 0

I’m working on an MVC3 Razor web application which gets it’s page decoration from a java content management system. As this decoration is shared by every page I’ve put the retrieval of the CMS content in the _Layout.cshtml file but I’m not entirely happy with the code I’ve 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>

As there is no controller for the _layout file I can’t see where else I could put the code to do the retrieval. Here are a few things that I’ve considered:

  • Retrieve the CMS content in separate pieces so I don’t need the LoadContent call. Unfortunately, because of the component I have to use to retrieve the CMS content this isn’t possible, it is all or nothing.
  • Use a partial view so I can utilise a controller. As I’d need to put the entire page into the partial that option just seems a bit ridiculous.
  • Call a single static method on some helper class which retrieves the data and adds the three sections to the ViewBag. That will allow me to move the code out of the view and feels like the best solution but I’m still not particularly happy with it.

Does anyone have any other suggestions/comments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:38:59+00:00Added an answer on May 31, 2026 at 5:38 pm

    You can use a global action filter to add the required data to the ViewBag in all controllers:

    public class LoadCmsAttribute : ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            if (!filterContext.IsChildAction &&
                !filterContext.HttpContext.Request.IsAjaxRequest() &&
                filterContext.Result is ViewResult)
            {
                var identity = new GenericIdentity("", "", true);
                var principal = new GenericPrincipal(identity, new string[] { });
                var cmsInterface = MvcApp.WindsorContainer.Resolve<ICMSInterface>();
                cmsInterface.LoadContent(principal, 2);
    
                var viewBag = filterContext.Controller.ViewBag;
                viewBag.HeadSection = cmsInterface.GetHeadSection();
                viewBag.FirstBodySection = cmsInterface.BodySection(0);
                viewBag.SecondBodySection = cmsInterface.BodySection(1);
            }
        }
    }
    

    Global.asax:

    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        ...
        filters.Add(new LoadCmsAttribute());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a text area in my form which accepts all possible characters from
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.