asp.net-mvc-3 – 如何在mvc3的dropdownlist中获取国家/地区列表
发布时间:2020-12-16 06:32:03 所属栏目:asp.Net 来源:网络整理
导读:我正在开发一个项目,在注册页面中我想获得一个列表 ?下拉列表中的所有国家/地区.任何人都可以告诉我我的意思 ?需要在Controller,View或其他任何需要的地方做?我有一个观点 注册页面 @model Retail_MVC.Models.registration@{ Layout = null;}div class="my_
我正在开发一个项目,在注册页面中我想获得一个列表
?下拉列表中的所有国家/地区.任何人都可以告诉我我的意思 ?需要在Controller,View或其他任何需要的地方做?我有一个观点 注册页面 @model Retail_MVC.Models.registration @{ Layout = null; } <div class="my_wrapper"> <div class="my_left_box"> @Html.LabelFor(model => model.username) </div> <div class="my_right_box"> <input type="text" id="txtusername" name="UserName"/> </div> </div> -- here i want to get dropdownlist for all countries 解决方法
使用
CultureInfo
// Namespaces You need using System.Globalization; using System.Linq; // GetCountries() method IEnumerable<string> GetCountries() { return CultureInfo.GetCultures(CultureTypes.SpecificCultures) .Select(x => new RegionInfo(x.LCID).EnglishName) .Distinct() .OrderBy(x => x); } EDITS class Country { public string ID { get; set; } public string Name { get; set; } } IEnumerable<Country> GetCountries() { return CultureInfo.GetCultures(CultureTypes.SpecificCultures) .Select(x => new Country { ID = new RegionInfo(x.LCID).Name,Name = new RegionInfo(x.LCID).EnglishName }) .GroupBy(c => c.ID) .Select(c => c.First()) .OrderBy(x => x.Name); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 确保登录用户只能看到他们的数据的最佳方法
- asp.net-mvc – 单元测试适配器抛出异常:无法在ASP.NET MV
- asp.net – .net MVC将linq数据从控制器传递到视图
- asp.net mvc更新多条记录
- asp.net-mvc – JsonIgnore在System.Web.Mvc.Controller中不
- ASP.NET MVC 3,如何做主题权限
- asp.net – 如何从Web应用程序中的客户端计算机获取AD凭据?
- Visual Studio对程序集签名时一个很不好用的地方
- 如何在ASP.NET中重命名文件?
- asp.net-mvc – 在C#中,我如何从一个字节[]中知道文件类型?
推荐文章
站长推荐
- 关于WCF的一个非常“无语”的BUG!
- asp.net-mvc – MVC3 DbContext保存后获取新模型
- asp.net-mvc – 发生异常后不要刷新会话 – NHib
- asp.net-core – 如何将HostBuilder用于WebJob?
- asp.net – dropdownlist在页面重新加载时不会重
- asp.net – 如何更改swagger文档基本URL?
- 我是否必须在ASP.NET中使用Viewstate
- asp.net-membership – ASP.NET成员资格 – 登录
- 什么OverrideAuthenticationAttribute是为什么?
- asp.net – 如何防止asp:Timer在生成响应之前发
热点阅读