Skip to content

Instantly share code, notes, and snippets.

@M-Yankov
Created November 3, 2017 07:52
Show Gist options
  • Save M-Yankov/fc15ddb0e54ac3667835e627f6df1498 to your computer and use it in GitHub Desktop.
Save M-Yankov/fc15ddb0e54ac3667835e627f6df1498 to your computer and use it in GitHub Desktop.
Differences between ViewBag, ViewData and model
  • With ViewBag (dynamic type):
    • Action: ViewBag.Message = "Hello World!";
    • View: @ViewBag.Message
  • With ViewData (dictionary)
    • Action: ViewData["message"] = "Hello World!";
    • View: @ViewData["message"]
  • With Strongly-typed views:
    • Action: return View(model);
    • View: @model ModelDataType;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment