November 2016
Intermediate to advanced
326 pages
6h 1m
English
We have just discussed how to pass the data from the Controller to the View using the Model object. While calling the View, we are passing the model data as a parameter. But there are times when you want to pass some temporary data to the View from the Controller. This temporary data may not deserve a model class. In such scenarios, we can use either ViewBag or ViewData.
ViewData is the dictionary and ViewBag is the dynamic representation of the same value.
Let us add the company name and company location property using ViewBag and ViewData as shown in the following code snippet:
public IActionResult Employee() { //Sample Model - Usually this comes from database Employee emp1 = new Employee { EmployeeId = 1, ...Read now
Unlock full access