c# - 如何对@Html.DropDownListFor 进行排序?

标签 c# asp.net-mvc

我想在 MVC C# 中对下拉列表进行排序。 这是我的下拉列表。所以我想按“FULLNAME”排序。

@Html.DropDownListFor(c => c.t_PEOPLE, 
                              new SelectList(Model.PEOPLE,
                                                 "KEY",
                                                 "FULLNAME", 
                                             Model.BOTKEY),
                                         new {onchange = "BusinessContact(this.value);" })

我该怎么做?

最佳答案

/* other code here.. */
new SelectList(Model.PEOPLE.OrderBy(x => x.FirstName),
                          // ^^^^^^^^^^^^^^^^^^^^^^^ this
/* rest of the code here */

关于c# - 如何对@Html.DropDownListFor 进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15800308/

相关文章:

c# - 为什么 C# 中的 IEnumerator<T> 需要两个 Current 方法?

c# - 在属性 setter 中执行业务规则的正确方法

c# - 如何调用多个请求到 http 服务器

css - 当我将源代码添加到 ASP.NET MVC 元素时,Bootstrap 容器未以实际大小显示

C# - 尝试将两个字节转换为 ushort 导致 "Cannot implictly convert type ' int' to 'ushort' "error

c# - SqlGeography.Reduce 方法如何工作?

c# - 未调用从 AuthorizeAttribute 覆盖 AuthorizeCore

.net - IIS 7.5 - 没有扩展名的文件导致错误 404.17

asp.net-mvc - 带有特殊字符的 MVC 路由

c# - Url.Action 不适用于非标准 MVC 路由