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:
2) The browser view doesn't show the value "Apple"
3) On further debug to my Next.cshtml
View:
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 ?