Passing Data From Controllers to Views (ViewBag & ViewData) – Session 19

Passing Data From Controllers to Views (ViewBag & ViewData) – Session 19

Golden Courses

55 лет назад

108 Просмотров

In this session of ASP.NET Core Tutorial, we are going to talk about passing data from Controllers to Views with ViewBag and ViewData. There is two different Views in terms of passing and processing data, Dynamic View and Strongly Typed View. In this session we describe both and show you passing data in Dynamic View.

Dynamic View Vs Strongly Typed View
Dynamic View (Weakly Typed View) is type of View which isn’t bound to any type of Models. Visual Studio doesn’t provide IntelliSense and Compile Time Error for this type of View. Thus, there is possibility of Run Time Error due to typos.

On the other hand, Strongly Typed View is type of View that is bound to a specific type of Model. Visual Studio provides IntelliSense and Compile Time Error for this type of View. This type of View is highly recommended and we will talk about it in further sessions.

ViewBag
One of the method that we can pass data from Controllers to Dynamic Views, is using of ViewBag. ViewBag uses Dynamic Property to store and restore data. Also, we do not need to cast data which is passed to View by ViewBag.

ViewData
Another way of passing data from Controllers to Weakly Typed Views is using ViewData. ViewData uses String Key for store and restoring data. Moreover data except String data should be casted in this method.

Tutorial Playlist
https://bit.ly/3lxQP9n

Our Social Media
Facebook: https://bit.ly/310ksqA
Instagram: https://bit.ly/3cOq4th
Telegram: https://bit.ly/3s4mzWc

Text Version of course:
https://www.goldencourses.net/passing-data-from-controller-to-view/

Тэги:

#ASP.NET_Core_Tutorial #ASP.NET_5.0 #MVC #CSharp #ViewBag #ViewData #Views #Controller
Ссылки и html тэги не поддерживаются


Комментарии: