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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:12:12+00:00 2026-06-13T23:12:12+00:00

All, In my application design, Some the actions of Controller classes will call the

  • 0

All, In my application design, Some the actions of Controller classes will call the same method firstly whenever it was called. the code snippet looks like below . please review it .thanks.

public class Controller1 : Controller
    {

        public ActionResult Action1()
        {
            FunctionA(); //This function must be called firstly.This function is defined somewhere. 
            return View("a1");
        }

        public ActionResult Action2()
        {
            FunctionA(); 
            return View("a2");
        }

    }

public class Controller2 : Controller
    {

        public ActionResult Action3()
        {
            FunctionA(); 
            return View("a3");
        }

        public ActionResult Action4()
        {
            FunctionB(); 
            return View("a4");
        }

    }

In current case , Action1,Action2 in Controller1 and Action3 in Controller2 will call the same FunctionA() , Based on the DRY theory, It is better to define a base controller or method something , I don’t know how to make it in Asp.net MVC4. Please help me .thanks.

  • 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-13T23:12:12+00:00Added an answer on June 13, 2026 at 11:12 pm

    Only you can answer this question because essentially the answer is dependant on your design.

    If your FunctionA method is specific to that controller then you could introduce a base class. However, you could alternatively use a helper class or even just an extension method (if it’s generic enough) to achieve your DRY architecture.

    In terms of how to call it in your action, if it must be run before the action is executed then I would suggest introducing a custom ActionFilterAttribute which you can use to decorate each action e.g.

    public class Controller1 : Controller
    {
        [FunctionAAttribute]
        public ActionResult Action1()
        {
            return View("a1");
        }
    
        [FunctionAAttribute]
        public ActionResult Action2()
        {
            return View("a2");
        }
    }
    

    Or if it has to be run before every action on that particular controller, just decorate the controller e.g.

    [FunctionAAttribute]
    public class Controller1 : Controller
    {
        public ActionResult Action1()
        {
            return View("a1");
        }
    
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when we write all our application methods and variables in a classes is nothing
First up, i realize this application has some design issues and while rewriting a
This is a question about Application design rather than how-to-do specific actions. I am
I am required to move some of our application configuration classes to XMLs. The
I have application which has some networking code which runs asynchronously. I have attached
I'm having some issues determining what the proper application design pattern is for initially
I am coding up some design time code. I want to use this snippet:
I am looking for some architectual design patterns for enterprise application development. I am
How can I list all instantiated objects in all application, using FASTMM4 or default
i want to get list of all application or Threads attached with a process.For

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.