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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:28:07+00:00 2026-05-16T10:28:07+00:00

tldr> Once a customer has been selected, how can all other controllers execute their

  • 0

tldr> Once a customer has been selected, how can all other controllers execute their actions always in the ‘context’ of that customer without manually passing the ID around?

I’m trying to figure out what the ‘right’ way is to handle the situation where one entire controller (or more) are all dependent on an idea from a previous controller. For instance, let’s say you were building some kind of customer management system. There’d be all kinds of customer functions, probably located on CustomerController. But then when you got into order management, you’d likely want to have an OrderController.

If you had only one OrderController, your methods would probably look like:

public ActionResult Edit(string id){…}

The id would be the id of the order, right? Where I get a little lost is when I need to get back to the customer. It’s like the ‘context’ of all the actions taking place are within the customer. You could do this by always adding the customer id onto actions (URLs):

http://site.com/Orders/Edit/1234?customerId=abc

But this seems like it gets quite tedious to be grabbing that value and jamming it onto every action. There are options like Session, but that seems sloppy.

What’s the right way to do this?

  • 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-16T10:28:08+00:00Added an answer on May 16, 2026 at 10:28 am

    If you really want to avoid storing your value into the session, you can use an action filter that takes care of the value. I’ve used this approach once and it goes like this:

    1. Create a new route that contains a placeholder for your value, e.g. customer id.
    2. When customer is selected, add the id to route for the next GET or POST call.
    3. Create an action filter that reads the id from route and adds it to action parameters before action takes place (OnActionExecuting). When action is done this same filter adds the id from action parameters back to route data (OnActionExecuted).
    4. Use this new action filter wherever you wish, probably at controller level.

    Now your customer id is easily persisted in the URL even though you do not manually add it to all links. If you need to use the customer id in an action method, you just add a parameter with the correct name. It is persisted over action method call even if you do not take it as a parameter.

    If you want to go further, in your new action filter you can get the data from database and add that to action parameters instead of adding only id. This way you can further simplify your action methods.

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

Sidebar

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.