开发者

What is the best way to populate DropDownLists with many entries in ASP.NET MVC

I ha开发者_如何转开发ve 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....


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜