在 ASP.NET MVC 中用许多条目填充 DropDownLists 的最佳方法是什么

发布于 2024-10-04 11:19:25 字数 219 浏览 0 评论 0原文

我有一个参与地址视图模型的 DropDownList。

最好将 170 个左右的国家/地区的列表存储在数据库中并将它们加载到视图模型上的集合中,还是将它们作为包含 SelectListItems 的集合硬编码到视图模型中更好?

哪个是最佳实践?

什么时候硬编码 SelectListItems 会变得太多,因为大多数人会选择硬编码姓名的标题:先生、小姐、女士和夫人......

I have a DropDownList that particpates in an Address View Model.

Is it best to store the list of 170 or so countries in a database and load them into a collection on the View Model, or is it better to hard code them into the View Model as a collection containing SelectListItems?

Which is best practice?

When does hardcoding SelectListItems become too many as most people would choose to hardcode the title of a name: Mr, Miss, Ms, and Mrs....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小ぇ时光︴ 2024-10-11 11:19:25

我绝对建议将它们放入数据库中。

ASP.Net MVC 有一些很好的缓存功能,因此使用这些功能您不会为每个访问该页面的用户实时调用数据库。

因此,由于数据调用可以被缓存,因此将它们放入数据库中并没有真正的缺点,而是有很多优点。

I would definitely advise putting them in a database.

ASP.Net MVC has some nice caching features so using those you won't be making a live call to your database for every user that hits that page.

So since the data call can be cached there is no real downside to putting them in the database but quite a few upsides.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文