Total Page Preview:   000000000369

What is Temp data in Asp.Net Core MVC in English and Hindi

Temp data in English

In ASP.NET Core MVC, TempData is a feature that allows you to store data that will be retained from one request to another. It's especially useful when you want to transfer data between actions or redirects. TempData is typically used to store temporary data like messages, errors, or any other information that you want to display to the user for a short period, often just for the next request.

Here's an example of how TempData can be used in ASP.NET Core MVC:
Let's say you have a simple controller with two actions, one to set a message in TempData and another to retrieve and display that message:
In this example, when the SetTempData action is invoked, it sets a message in TempData and then redirects to the GetTempData action. The GetTempData action retrieves the message from TempData and displays it using the ViewData dictionary in a corresponding view.
Here's an example of how you might set up the corresponding view for the GetTempData action:
When the SetTempData action is triggered, it sets a message in TempData and then redirects to the GetTempData action. The GetTempData action retrieves the message from TempData and displays it on the view. TempData is useful when you want to show a message to the user after a redirect or after an action that changes the state. Remember that TempData is meant for temporary data and is cleared once it's read.
 
Temp data in Hindi
ASP.NET Core MVC mein TempData ek feature hai jo aapko data ko ek request se dusre request tak retain karne ki anumati deta hai. Ye khaaskar tab kaam aata hai jab aap actions ya redirects ke beech mein data transfer karna chahte hain. TempData aam taur par temporary data ko store karne ke liye istemal hota hai, jaise ki messages, errors, ya kisi aur information ko jo aap chhote samay ke liye user ko dikhana chahte hain, adhiktar bas agle request ke liye.
 
Yahan ek ASP.NET Core MVC mein TempData ka istemal karne ka example diya gaya hai:
 
Maan lijiye aapke paas ek simple controller hai jisme do actions hain, ek TempData mein ek message set karne ke liye aur doosra message ko retrieve aur display karne ke liye:
Is example mein, jab SetTempData action ko invoke kiya jata hai, ye TempData mein ek message set karta hai aur phir GetTempData action mein redirect karta hai. GetTempData action, TempData se message ko retrieve karta hai aur ViewData dictionary ka istemal karke usse view mein display karta hai.
Yahan GetTempData action ke corresponding view ko setup karne ka ek example diya gaya hai:
Jab SetTempData action trigger hota hai, ye TempData mein ek message set karta hai aur phir GetTempData action mein redirect karta hai. GetTempData action, TempData se message ko retrieve karta hai aur use view par display karta hai. TempData ka istemal tab kiya jata hai jab aap redirect ke baad ya state ko change karne wale action ke baad user ko kuch dikhana chahte hain. Yaad rakhein ki TempData temporary data ke liye hai aur ise read karne ke baad clear ho jata hai.

 

 

 

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com



Comments


                           
                           

                           

                           

Facebook User: