ttmind

Main Navigation

ttmind
  • jim-jams
  • Tech
  • Positive
Login

Login

Facebook Google

OR

Remember me Forgot password?

Don't have account? Signup here.

Sort by Categorys

.Net

PHP

Java

JavaScript

Database

Server

Client Side

Tools

Artificial Intelligence

Cloud

Hybrid Development

Event

Smart City

Education

Security

Scrum

Digital Marketing

APP Development

Business

Internet

Simulation

Art

Network

Microservices

Architecture

Technology

Leadership

    Top Articles

  • How Does Social Media Bring People Together?
    TTMind Author
  • How to read appSettings JSON from Class Library in ASP.NET Core
    Anil Shrestha
  • Printing Support In Asp.Net Core
    TTMind Author
  • HOW TO EXTRACT TEXT FROM IMAGE USING JAVASCRIPT (OCR with Tesseract.js)?
    Prakash Pokhrel
  • Images Upload REST API using ASP.NET Core
    Prakash Pokhrel
  • Related Topic

  • How to read appSettings JSON from Class Library in ASP.NET Core
  • Printing Support In Asp.Net Core
  • Images Upload REST API using ASP.NET Core
  • How to use IActionFilter, IAsyncActionFilter in ASP.NET Core MVC?
  • ASP.NET CORE - Blazor CRUD operation using ADO.NET
  • Tech
  • About Us
  • Contact Us
  • TechHelp
  • PositiveHelp
  • Jim-Jams Help
  • Terms & Conditions

© Copyright ttmind.com

Main Content

Difference Between ViewData, ViewBag and TempData in Asp.net MVC

.Net MVC about 8 years ago || 4/9/2018 || 2.0 K View

  • Hide

In Asp.Net MVC there are three ways to pass/store data between the controllers and views.

ViewData: -

  •  ViewData is used to pass data from one controller to another view.
  • It is available for the current request only.
  • Requires typecasting for complex data type and checks for null values to avoid error.
  • If redirection occurs, then it becomes value null.

ViewBag: -

  • ViewBag is also used to pass data from the one controller to another respective view.
  • ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.
  • It is also available for the current request only.
  • If redirection occurs, then after value becomes null.
  • Doesn’t require typecasting for complex data type.

TempData: -

  • TempData is derived from TempDataDictionary class.
  • TempData is used to pass data from the current request to the next request.
  • It keeps the information for the time of an HTTP Request. This means only from one page to another. It helps to maintained data when we move from one controller to another controller or from one action to another action.
  • It requires typecasting for complex data type and checks for null values to avoid error. Generally, it is used to store one-time messages like the error messages and validation messages.

 

  • 3
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

TTMind Author

TTMind Author

CEO, Consultant, Other

ASP.NET

Reset Your Password
Enter your email address that you used to register. We'll send you an email with your username and a link to reset your password.

Quick Survey