When to use ViewBag, ViewData, or TempData in Mvc3

后端 未结 2 1018
予麋鹿
予麋鹿 2020-12-16 17:30

When to use ViewBag, ViewData, or TempData in view. In the controller i want to send object to the view.I want to know that which will be best in this case. I want the objec

2条回答
  •  执念已碎
    2020-12-16 18:06

    IMHO for decent design practies -

    ViewBag = never. ViewData = never. These are magic string-ish based fields and canot be caught during any compile time instances either.

    Your VieWModel should contain everything it needs. Thats it's purpose in life. Don't devoid it of its purpose. TempData for status messages only or object you don't want to cache but wan't available for the very next request only.

提交回复
热议问题