为什么不使用ViewBag严重?

编程入门 行业动态 更新时间:2024-10-25 22:34:24
本文介绍了为什么不使用ViewBag严重?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我用MVC3页面太多ViewBag什么?什么极端的问题会在那里,如果我继续大量使用它们。在少言,什么是ViewBag的缺点,什么是替代呢?

解决方案   

什么是它的备用?

您应该只使用ViewModels,这是推荐的方法。创建强类型的意见。它将使你的code更清洁,易于维护。

  

什么极端的问题,将在那里?

问题与Viewbags / ViewData的是编译时检查。 ViewBags只是字典,你不会知道,直到左右运行时的任何问题,因此它使你的code容易出错。所以,总是试图去用的ViewModels。

What if i use too many ViewBag in MVC3 page? What extreme problems will be there if i continue use them heavily. In less words, what are the disadvantages of ViewBag and what is the alternate for it?

解决方案

what is the alternate for it?

You should only use ViewModels, It's the recommended approach. Create Strongly typed views. It would make your code cleaner and easy to maintain.

What extreme problems will be there?

Issue with Viewbags/ViewData is compile time checking. ViewBags are just dictionaries and you won't be aware about any issues until run time and thus it makes your code error-prone. So always try to go with ViewModels.

更多推荐

为什么不使用ViewBag严重?

本文发布于:2023-11-25 03:09:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628077.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ViewBag

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!