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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:41:53+00:00 2026-05-28T04:41:53+00:00

I am trying to pass a random string from my Controller to the View

  • 0

I am trying to pass a random string from my Controller to the View.

Here is my Controller code:

 [HttpPost]
    public ActionResult DisplayForm(UserView user)
    {
       //some  data processing over here
        ViewData["choice"] = "Apple";

        return RedirectToAction("Next", "Account");
    }

Now I want to pass that data value “Apple” to my view Next.cshtml which is created as follows:

//View: Next.cshtml

  @{
    ViewBag.Title = "Thanks for registering";
    Layout = "~/Content/orangeflower/_layout.cshtml";
   }
    <p>Your favorite fruit is:</p>@ViewData["choice"]

But I am not able to see my data in the browser when the project runs.

Here is the snapshot:

1) On debug, the controller showing the value:

enter image description here

2) The browser view doesn’t show the value “Apple”

enter image description here

3) On further debug to my Next.cshtml View:
enter image description here

Why is the value not getting passed to the View correctly. Both my controllers for Next and DisplayForm are within the same Controller AccountController.cs , still value not getting displayed.

Can someone help me solve 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-28T04:41:53+00:00Added an answer on May 28, 2026 at 4:41 am

    You are not rendering a view, you are redirecting. If you wanted to pass some information tyo the view you need to return this view after adding it to ViewData:

    [HttpPost]
    public ActionResult DisplayForm(UserView user)
    {
        //some  data processing over here
        ViewData["choice"] = "Apple";
    
        return View();
    }
    

    If you want to pass a message that will survive after a redirect you could use TempData instead of ViewData.

    [HttpPost]
    public ActionResult DisplayForm(UserView user)
    {
        //some  data processing over here
        TempData["choice"] = "Apple";
    
        return RedirectToAction("Next", "Account");
    }
    

    then inside the Next action you could fetch the data from TempData and store it inside ViewData so that the view can read it.

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

Sidebar

Related Questions

I am trying to pass a string (or char*) from Rundll32 to a DLL
I'm trying to pass big strings of random html through regular expressions and my
I'm trying to pass big strings of random html through regular expressions and my
I'm trying to pass in a Base64 string into a C#.Net web application via
I'm trying to pass a null value for the first parameter in the code
Wondering what I am doing wrong here. I am trying to pass an integer
i am trying to pass a string through the XmlHttp method. Let me show
Hey everbody, im getting some trouble here. Well, im trying to pass a value
I have the following code which turns a string, that I pass into the
I'm trying to pass an ArrayList iterator to a JSP from a Spring class,

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.