D
D
Dmitry Smolyakov2015-10-18 14:07:12
ASP.NET
Dmitry Smolyakov, 2015-10-18 14:07:12

What is the difference between ViewBag and @Model?

With @Model it is possible to call only the properties of the model, but with the help of ViewBag / ViewData it is possible to call the data generated by the controller?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mike, 2015-10-18
@Goodilla

ViewBag/ViewData - can be transferred and used throughout the page, in all templates, while the model can only be expanded in the template called by the current controller.
Also, ViewBag differs from ViewData in the way data is stored, if "objects" are specified in the first, then in the second, data can be called and stored as in an array. (ViewData["data"], ViewBag.data).

A
Aram Aramyan, 2015-10-23
@GreenBee

The Model is strongly typed and designed specifically for this View (only available inside the View)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question