Holding value between multiple pages Holding value between multiple pages vue.js vue.js

Holding value between multiple pages


You can use TempDataDictionary to pass data from the controller to the view and back. It's a Dictionary, so you can access it with a key:

TempData["HoldDate"] = new DateTime(2020, 2, 13);

When you read data normally from TempData, it is automatically marked for deletion with the next HTTP request. To avoid that, since you want to pass this data around, use the .Peek() method, which lets you read the data but does not mark it for deletion.

var date = TempData.Peek("HoldDate");


If you need data to persist during the entire user session, you can use Session. For example user id or role id.

if(Session["HoldDate"] != null) {    var holdDate= Session["HoldDate"] as DateTime;}

If you need data only persist a single request - TempData. Good examples are validation messages, error messages, etc.

if (TempData.ContainsKey("HoldDate")){    var holdDate = TempData["HoldDate"] as DateTime;}

TempData and Session, both required typecasting for getting data and check for null values to avoid run time exception.