ViewBag 与之前的 ASP.NET MVC 1 和 2 中的 ViewData 是一样的。它只是恰好是动态的,而不需要像带键的字典一样使用它。我认为这根本不会取代强类型视图,事实上您应该尽可能少地使用 Viewdata/Viewbag。尽可能始终使用强类型视图,因为如果 Viewdata/Viewbag 中的名称发生更改,并且不会在各处进行 ViewData 强制转换,则会导致更少的错误,并使 HTML 更清晰。
The ViewBag is the same thing as ViewData in previous ASP.NET MVC 1 and 2. It just happens to be dynamic instead of needing to use it like a dictionary with keys. I don't think this will replace strongly typed views at all and in fact you should use Viewdata/Viewbag as little as possible. Always use strongly typed views whenever possible since it will lead to fewer errors if the names in your Viewdata/Viewbag change and make the HTML cleaner by not having ViewData casts all over the place.
发布评论
评论(1)
ViewBag 与之前的 ASP.NET MVC 1 和 2 中的 ViewData 是一样的。它只是恰好是动态的,而不需要像带键的字典一样使用它。我认为这根本不会取代强类型视图,事实上您应该尽可能少地使用 Viewdata/Viewbag。尽可能始终使用强类型视图,因为如果 Viewdata/Viewbag 中的名称发生更改,并且不会在各处进行 ViewData 强制转换,则会导致更少的错误,并使 HTML 更清晰。
The ViewBag is the same thing as ViewData in previous ASP.NET MVC 1 and 2. It just happens to be dynamic instead of needing to use it like a dictionary with keys. I don't think this will replace strongly typed views at all and in fact you should use Viewdata/Viewbag as little as possible. Always use strongly typed views whenever possible since it will lead to fewer errors if the names in your Viewdata/Viewbag change and make the HTML cleaner by not having ViewData casts all over the place.