What is actually a ViewBag point?

In an ideal "hello world," you need to pass a strongly typed model back to the view.

return View(MyModel);

If everything gets sticky, we can create

ViewModel

return View(MyViewModel);

ex.

Myviewmodel

  • Mymodel
  • Foo

I can avoid creating the whole ViewModel

and partially use ViewBag.

ViewBag.Foo = Foo;
return View(MyModel);

I understand that I will lose some strongly typed functions

(e.g. Intellisense)

in my view for this ViewBag.

Is this approach sloppy? vs MVC mean?

If so, what is the actual ViewBag point?

+4
source share
3 answers

, , - , , . ViewBag . , , , . / .

ViewBag . .

+4

, , , - - , , "" . dynamic , , ViewBag , ViewData[]/ViewModel , .

+1

, ViewBag ( ). , . ViewModel, ViewModels. ..

, ViewBag : - ASP.NET MVC . , .

+1
source

All Articles