ViewData is a dictionary-like container in ASP.NET Core used to pass data from a controller action to a view. It is typically used for one-way communication from the controller to the view.
Example:
ViewData["Message"] = "Hello from ViewData!";
ViewBag
ViewBag is a dynamic property in ASP.NET Core that is used to pass data from a controller to a view. It's similar to ViewData but provides a more concise way to access data in views.
Example:
ViewBag.Message = "Hello from ViewBag!";
TempData
TempData is used to store data temporarily across multiple requests. It is often used for scenarios like redirecting to another action and carrying data along with the request.
Example:
TempData["Message"] = "Hello from TempData!";
Session
Session in ASP.NET Core allows you to store user-specific data that persists across multiple requests. It provides a way to maintain user state.
Cookies are small pieces of data stored on the user's browser. They can be used to store information like user preferences or authentication tokens.
Example:
Response.Cookies.Append("Username", "MohanKumar", new CookieOptions { Expires = DateTime.Now.AddHours(1) });
Query String
The query string is a part of a URL that allows you to pass data to a server in key-value pairs. It's commonly used to send data to a web application via URL parameters.