My application reads barcodes from a USB scanner. I treat them as tokens and then build commands from those tokens. There may be a situation that I need 2 or more reads before I can create a command. I need to store previous reads in some way. How can I keep some data between request? I do not to use that tokens in my view.
Only results of commands may be displayed in the view.
TempData is used to pass data from current request to subsequent request (i.e., redirecting from one page to another). Its life is too short and lies only till the target view is fully loaded. But you can persist data in TempData by calling the method Keep () .
There are a number of ways in which you can pass parameters to action methods in ASP.NET Core MVC. You can pass them via a URL, a query string, a request header, a request body, or even a form. This article talks about all of these ways, and illustrates them with code examples.
You may fetch TempData in your view and store in a variable. If you set a TempData in your action method and if you read it in your view and call the "Keep" method then TempData will be persisted and will be available in next request. We can save TempData value using keep method after reading value from TempData.
The TempData
dictionary is ideal for storing data between controller actions. It's most commonly used in the Post/Redirect/Get pattern but could apply here.
This is a good article to read about it: http://www.devcurry.com/2012/05/what-is-aspnet-mvc-tempdata.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With