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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:20:23+00:00 2026-06-17T10:20:23+00:00

MVC 4 I have an action filter that I want applied only to the

  • 0

MVC 4
I have an action filter that I want applied only to the Index and Edit methods in my base controller, but the action filter does not fire when I apply it to the Index and Edit methods. It DOES work however if I apply the filter at the class level.

Base Controller:

//[SetAreaControllerFilter]  <------ does fire here
    public class BaseControllerSingle<TRepository, TViewModelSingle> : BaseController

    [SetAreaControllerFilter]  <----- doesn't fire here
    public ActionResult IndexBase(TViewModelSingle viewModel, string pageTitle)
    {
        ViewBag.Header = pageTitle;
        return View(viewModel);
    }

Derived class call to base:

public ActionResult Index()
        {
            ItemViewModel viewModel = _manageItemsAppServ.CreateNewViewModel(CurrentCompanyId);
            viewModel.DDLOptions = _manageItemsAppServ.CreateFilterOptionsViewModel(CurrentCompanyId);
            return base.IndexBase(viewModel, "Manage Materials");
        }

Action Filter:

public class SetAreaControllerFilterAttribute : ActionFilterAttribute, IActionFilter 

 {
      public override void OnActionExecuting(ActionExecutingContext filterContext)
      {
          //Set variable to be used by view and partials
           dynamic viewBag = filterContext.Controller.ViewBag;

           viewBag.AreaName = (string)filterContext.RouteData.DataTokens["area"]; //used by OTIS.Core.js to create links
           viewBag.ControllerName = (string)filterContext.RouteData.Values["controller"]; //used by Toolbar adn OTIS.Core.js to create links
      }
}
  • 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-06-17T10:20:24+00:00Added an answer on June 17, 2026 at 10:20 am

    Well it appears that there is NOT a way to apply a filter to an action in a base controller. You need to apply it at the class level or to the actions in the derived controller class. This does not seem like it should be this way, but no one has been offer a solution that works.

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

Sidebar

Related Questions

ASP.Net MVC Controllers have several methods of forwarding control to another controller or action.
I have an ASP.NET MVC 3 controller action. That action is defined as follows:
I have an MVC app that is working fine, but I now want to
I have an ASP.net MVC controller called Designs that has an action with the
I have an action filter in an ASP.NET MVC 3 app that needs some
Suppose I have an action that returns an rendered asp.net mvc control and send
I have an asp.net mvc action that returns a file result. Behind the scenes,
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have a div called test and mvc action in the client controller The
I have a jquery routine that calls an MVC action which will do a

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.