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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:30:01+00:00 2026-06-08T17:30:01+00:00

I have a base Controller like follow public abstract class BaseController { protected ActionResult

  • 0

I have a base Controller like follow

 public abstract class BaseController
    {

        protected ActionResult LogOn(LogOnViewModel viewModel)
        {
            SaveTestCookie();

            var returnUrl = "";
            if (HttpContext != null && HttpContext.Request != null && HttpContext.Request.UrlReferrer != null)
            {
                returnUrl = HttpContext.Request.UrlReferrer.LocalPath;
            }

            TempData["LogOnViewModel"] = viewModel;


            return RedirectToAction("ProceedLogOn", new { returnUrl });
        }

        public ActionResult ProceedLogOn(string returnUrl)
        {
            if (CookiesEnabled() == false)
            {
                return RedirectToAction("logon", "Account", new { area = "", returnUrl, actionType, cookiesEnabled = false });
            }
            var viewModel = TempData["LogOnViewModel"] as LogOnViewModel;

            if (viewModel == null)
            {
                throw new NullReferenceException("LogOnViewModel is not found in tempdata");
            }

            //Do something
            //the problem is I missed the values which are set in the ViewBag
        }
    }

and another Controller

public class MyController : BaseController
    {

        [HttpPost]
        public ActionResult LogOn(LogOnViewModel viewModel)
        {
            // base.LogOn is used in differnet controller so I saved some details in view bag 

            ViewBag.Action = "LogonFromToolbar";
            ViewBag.ExtraData = "extra data related only for this action";

            return base.LogOn(viewModel);
        }

    }

the problem is I missed the view bag values in ProceedLogOn action method.
I have the values in Logon method in BaseController.

How can I copy the values of ViewBag from one Action to another Action?

So I can not simply say this.ViewBag=ViewBag;

because ViewBag doesn’t have setter. I was thinking of Iterating through viewbag.
I tried ViewBag.GetType().GetFields() and ViewBag.GetType().GetProperties() but they return nothing.

  • 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-08T17:30:02+00:00Added an answer on June 8, 2026 at 5:30 pm

    ViewData reflects ViewBag
    You can iterate the values you’ve stored like this :

    ViewBag.Message = "Welcome to ASP.NET MVC!";
    ViewBag.Answer = 42;
    
    foreach (KeyValuePair<string, object> item in ViewData)
    {
        // if (item.Key = "Answer") ...
    }
    

    This link should also be useful

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

Sidebar

Related Questions

I have a base class looking like this: public class BaseController : Controller {
I have abstract BaseController, which basically looks like below: public abstract class BaseController :
I have the following code: public abstract class BaseController : Controller { public IUserService
Lets say I have a controller class like this. public class InStorePickupController : Controller
Imagine that I have a Spring MVC controller something like this: @Controller @RequestMapping(/base-url) public
I have a base controller class and I would like to pass a Message
I have a base class: class motorcycle { public: virtual int speed() { return
I have a controller that overrides OnActionExecuting and does something like this: protected override
I have a model setup like so: class Item < ActiveRecord::Base belongs_to: media def
I have a base controller class: And all my other controller inherits this BaseClass

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.