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 3955498
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:14:25+00:00 2026-05-20T02:14:25+00:00

My Original Issue here: Help! I've got repository access in my MVC master page!

  • 0

My Original Issue here:

Help! I've got repository access in my MVC master page! Refactor time!

What originated as a re factoring job to improve performance has revealed new issues. If I should keep this in my original question – feel free to delete this one, and rename the old one to something more relevant. I’m using an ActionFilter applied to a base controller to load some user-customized settings. My issue is that I save these settings in the filterContext.Controller.ViewData object but its coming through as null on my master page. Here is the relevant code:

Action Filter

 [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public class StoreSettingsActionFilter : ActionFilterAttribute
{
    private readonly IResellerRepository _resellerRepository;
    private readonly IStoreSettingsRepository _storeSettingsRepository;

    public StoreSettingsActionFilter(
        IResellerRepository resellerRepository,
        IStoreSettingsRepository storeSettingsRepository
    )
    {
        _resellerRepository = resellerRepository;
        _storeSettingsRepository = storeSettingsRepository;
    }

    public StoreSettingsActionFilter()
        : this(new ResellerRepository(), new StoreSettingsRepository())
    {

    }

    public override void OnResultExecuted(ResultExecutedContext filterContext)
    {
        base.OnResultExecuted(filterContext);

        var settingsViewModel = new StoreSettingsViewModel();
        settingsViewModel.ThemeLocation = "~/Content/jquery-ui-1.8.9.custom.css";
        var user = filterContext.HttpContext.User;
        if (!user.Identity.IsAuthenticated || !user.IsInRole("Reseller"))
        {
            filterContext.Controller.ViewData["storeSettings"] = settingsViewModel;
            return;
        }

        var session = filterContext.HttpContext.Session;
        var reseller = session["reseller"] as Reseller;
        if (reseller == null)
        {
            reseller = _resellerRepository.GetResellerByUsername(user.Identity.Name);
            session["reseller"] = reseller;
        }

        if (reseller.StoreSettingsID != null && reseller.StoreSetting.Theme != null)
        {
            var storeSettings = session["storeSettings"] as StoreSettings;
            if (storeSettings == null)
            {
                storeSettings = _storeSettingsRepository.GetStoreSettings((int)reseller.StoreSettingsID);
                session["storeSettings"] = storeSettings;
            }
            // Using AutoMapper to convert between the model and the view model
            //settingsViewModel = Mapper.Map<StoreSettings, StoreSettingsViewModel>(storeSettings);

            settingsViewModel.ThemeLocation = storeSettings.Theme.StylesheetLocation;
            settingsViewModel.Address1 = storeSettings.Address1;
            settingsViewModel.Address2 = storeSettings.Address2;
            settingsViewModel.City = storeSettings.City;
            settingsViewModel.FooterImage = storeSettings.Image.FileName;
            settingsViewModel.HeaderImage = storeSettings.Image1.FileName;
            settingsViewModel.Phone = storeSettings.Phone;
            settingsViewModel.PostalCode = storeSettings.PostalCode;
            settingsViewModel.ProvinceCode = storeSettings.Province.Abbreviation;
            settingsViewModel.StoreName = storeSettings.StoreName;
        }
        filterContext.Controller.ViewData["storeSettings"] = settingsViewModel;
    }
}

Base Controller

[StoreSettingsActionFilter]
public abstract class BaseController : Controller
{

}

HomeController snippet

public class HomeController : BaseController
{
    //
    // GET: /Store/Home/
    public ActionResult Index()
    {
        IProductRepository productRepository = new ProductRepository();
        var products = new List<Product>();

        IResellerRepository resellerRepository = new ResellerRepository();
        var reseller = resellerRepository.GetResellerByUsername(User.Identity.Name);

        IProductCategoryRepository categoryRepository = new ProductCategoryRepository();
        var categories = categoryRepository.GetProductCategoriesFromStoreSettings(reseller.StoreSetting.Categories);

        foreach(var category in categories)
        {
           products.AddRange(productRepository.GetProductsByCategory(category.CategoryId));
        }

        var viewModel = new StoreViewModel()
                            {
                                Products = products.ToList()
                            };

        return View(viewModel);
    }
}

Master Page snippet

<head id="Head1">
<% 
var storeSettings = (StoreSettingsViewModel)ViewData["storeSettings"]; // This is always ending up null.
%>
<title>
     <%: string.IsNullOrEmpty(storeSettings.StoreName) ? "My Store Name" : storeSettings.StoreName%>
</title>

I’m really stuck here, your help is greatly 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-20T02:14:26+00:00Added an answer on May 20, 2026 at 2:14 am

    Try overriding OnActionExecuted instead of OnResultExecuting in the StoreSettingsActionFilter filter:

    public override void OnActionExecuted(ActionExecutedContext filterContext)
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Refer original post here for a reference to the original issue. What plugin should
Here's a bit subtle issue I'm dealing with, and would appreciate any help. We
Note I have completely re-written my original post to better explain the issue I
Ive gotten some great help here and I am so close to solving my
I am having some weird issue here. I have a database table which has
Hopefully, someone here can give me some light. I have been researching this issue
I have an unusual CSS issue in IE7. Here's my html and css code:
I have a bit of an issue here. I have a Python script which
Ok so here is my issue. I have to HashSet 's, I use the
I've got an issue when using an extjs combo box (regardless of browser, tested

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.