Skip to main content

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

Senior .NET Core
Quick Answer TempData survives exactly one redirect. Set it before RedirectToAction(); read it in the destination action or view. ViewData is a dictionary รขโ‚ฌโ€ controller sets it, view reads it within one request. ViewBag is dynamic syntax over ViewData (ViewBag.Title = "X" is ViewData["Title"] = "X"). TempData uses cookie or session; the others don't persist.

Answer

ViewData/ViewBag: For same request only.
TempData: Persisted across redirects using cookies or session. Ideal for one-time messages.

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