Skip to main content

What is TempData and how is it different from ViewData/ViewBag?

Senior .NET Core
Quick Answer TempData persists across a redirect รขโ‚ฌโ€ set before redirecting, read in destination. Useful for success/error messages after form submissions. ViewData: dictionary for current request (controller sets, view reads). ViewBag: dynamic property syntax over ViewData. TempData uses either cookie or session backend. All three are for controller-to-view communication.

Answer

ViewData/ViewBag: Per-request data.

TempData: Persists across redirects until consumed. Backed by cookies or session.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice