MVC ViewBag Best Practice

前端 未结 10 1915
野趣味
野趣味 2020-11-29 01:42

For the ViewBag, I heard it was a no-no to use. I would assume have the content from the ViewBag should be incorporated into a view model?

Question:

  1. <
10条回答
  •  野性不改
    2020-11-29 02:00

    1) Is my assumption above the best practice. (Not to use a ViewBag and second to have it in the view model)

    Yes.

    2) Are there situations where a ViewBag is absolutely necessary?

    No. Everything that you have stored in a ViewBag could go into the view model passed to the view.

提交回复
热议问题