What you going to do is To fill the ViewData["page"]
Within the your action then pass it to View. since it only lives within your Controller [Action] -> View
. then Store it within an element (It can be a Hidden Input) like:
<input type="hidden" name="ID" value=@ViewData["page"] id="ID" />
Then If you wish to receive it Within your Next ActionResult you can easily Call the FormCollection
like below and take the Value from the Hidden Input:
public ActionResult Example(FormCollection form)
{
var id = form["ID"];
}
Thats how it works with ViewData and ViewBag. However; If you want to Directly use the data within another action I recommend using TempData
like below:
TempData["page"] = pageData;
There are number of other ways to receive the data within your other action as well such as Cookies
, And Sessions
but Unless you do not want to go to many trouble i recommend TempData
.
UPDATE
Use Session
, Next easiest option would be Session
It works like below:
Create:
Session["page"] = YourValue;
Read:
//You can easy cast it to your type or Convert it.
var _strValue = Sessions["page"].ToString() //if its string