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

  • Home
  • SEARCH
  • 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 4270326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:17:27+00:00 2026-05-21T07:17:27+00:00

On my MVC3 _Layout.cshtml page I show a banner image like this <body> <div

  • 0

On my MVC3 _Layout.cshtml page I show a banner image like this

    <body>
    <div id="page">
        <div id="nonFooter">
            <div id="header">
               <img id="headerBanner" src="@Url.Content("~/Content/Images/banner.jpg")" alt="Banner" />
            </div> ....

Simple enough.

What I want to do is display a different image for each client using the site, most likely this will be determined by the url, eg: http://www.mysite.com/clientA/Home (clientA determines which image to be used)

Essentially the desired functionality is a bit CMS like but we don’t need a full blown CMS, we just need to replace a few images and colors.

So the question is what is the best way to do this?

My thinking so far is to use jQuery to update the src like this

<script type="text/javascript">
$(document).ready(function () {
    $('#headerBanner').attr('src', whatToPutHere? );
});    

But I’m stuck on ‘best practice’ for the whatToPutHere.

Should it be…

  • An image put in the ViewBag in the serverside code (eg. @ViewBag.BannerImage)?
  • An image put in the ViewModel?
  • Some kind of server call to get/load the image (logic to determine which image to use must be server side)…(would this be another round trip though?)?
  • …another approach?

Any help much appreciated 🙂

  • 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-21T07:17:28+00:00Added an answer on May 21, 2026 at 7:17 am

    I would use only server side code to generate the user specific image URL. I would not use ViewBag or model to pass the data to View, since it’s in the _Layout page. In the example below there are static methods for simplicity. If you bother about unit testing it need refactoring with non-static methods instead.

    In _Layout.cshtml:

    <img src="@AccountServices.BannerUrl" alt="Banner" />
    

    In AccountServices.cs

    public class AccountServices
    {
       public static string BannerUrl
       {
          get{
              // Your code to form the image URL, may be the following:
              var bannerPathTemplate = "/images/banners/user-{0}.jpg";
              var user = CurrentUser;              
              if (user != null)
              {
                  return string.Format(bannerPathTemplate, user.Id);
              }
              return string.Format(bannerPathTemplate, "unauthorized");              
          }
       }
    
       const string sessionKeyUser = "session-current-user";
    
       public static User CurrentUser
       {
           get{
               if (HttpContext.Current.Session[sessionKeyUser]==null){
                   // HERE insert code to get the current **user** object from db                   
                   HttpContext.Current.Session[sessionKeyUser] = user;
               }
               return (User)HttpContext.Current.Session[sessionKeyUser];
           }
       }
    
    }
    

    Another approach to get the banner HTML I would use is @Html.RenderAction(“your action”, “your controller”).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HtML section in _Layout.cshtml <div id=header> <div class=logo><a href=#><img src=@Url.Content(~/!(IMAGEPATH)!/logo.png) alt= /></a></div> <div class=fb_like><img
When mvc3 was created I placed one of these on my _layout.cshtml page... @Html.RenderCss()
This is an MVC3 web application. In the _Layout.cshtml shared view, there is a
In my ASP.NET MVC3 project I have a standard _Layout.cshtml generated by Visual Studio
I have a MVC 3 project in which I use _Layout.cshtml as master page
I am learning the ASP.NET MVC 3 Framework. In my layout page ( _Layout.cshtml
I call the same controller many times from _Layout.cshtml view. So in this controller,
I passed my querystring in _Layout.cshtml page <li>@Html.ActionLink(Shopping, Index1, new { controller = Shopping,
Could i include a single page .cshtml in a MVC3 app (without controller)? I
In MVC3, i created one register form. I created one model,,controller and view. This

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.