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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:50:02+00:00 2026-05-18T06:50:02+00:00

My controller has abstract base controller. I want to access the form post data

  • 0

My controller has abstract base controller. I want to access the form post data inside abstract base class constructor. How can we do that ?

public abstract class AppController : Controller  
{  
    public AppController()   
    {
        // request post data required here  
    }  
}  

public class ProductController : AppController  
{  
    public ProductController() {  }  
}  

Purpose : Updating second dropdown on change of first dropdown. Both are on MASTER page.

Code given above is one of the 2 options to pass data to master page:

  1. Add using ViewData in ALL the action methods.
  2. Do it in only one place using abstract base controller – add the required data using ViewData inside its constructor and make our main controller class implement this abstract base controller class. So that we don’t have to add the viewdata for master page in all action methods.
  • 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-18T06:50:03+00:00Added an answer on May 18, 2026 at 6:50 am

    I don’t know what is your final goal with this but this is something which is not recommended to be done in MVC. The Request object is not yet initialized in the constructor of the controller. You could try to use the native HttpContext object:

    string foo = System.Web.HttpContext.Current.Request["foo"];
    

    but that’s something extremely bad and I would never recommend you doing this as now your controller is coupled to the static native HttpContext instance without any chance of unit testing it.

    Instead of using the constructor you could override the Initialize method of your controller where you will have access to the request context and you could read posted data:

    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        base.Initialize(requestContext);
        string foo = requestContext.HttpContext.Request["foo"];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a C++ app which internally has some controller objects that
I have a Rails application that unfortunately after a request to a controller, has
I am using the Zend Framework. I have a controller named 'UserController' that has
I'm struggling here with a problem: I have a controller questions which has action
I have an XHTML strict page that has an invisible div that is controlled
My Controller class is decorated with an AuthorizeAttribute to protect the actions: [Authorize(Roles =
I want my controller to return the right HTTP response code when the user
I came across a controller in an older set of code (Rails 1.2.3) that
So the controller context depends on some asp.net internals. What are some ways to
Given a controller method like: def show @model = Model.find(params[:id]) respond_to do |format| format.html

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.