Showing posts with label ViewDataDictionary. Show all posts
Showing posts with label ViewDataDictionary. Show all posts

Tuesday, March 5, 2019

Passing data from Controller to View

There are different ways to pass values / objects from a controller to a view in Asp.Net Core MVC. Following are some of the commonly used ways.

ViewData – Returns a ViewDataDictionary, allows us to store key-value pairs in the controller and access them in the view. The key is a case sensitive string and the value can be any type int/string/object etc. When we use ViewData to pass custom objects we need to cast them in the View before using the properties.