在 MVC 中按字母顺序对 SelectList 进行排序
问题是我的选择列表可能有数据(加上它的格式类似于[福特IV 200 xyx]),我想在其中退休(通过仅显示在第三列中具有一点值 true 的记录,这也是我需要弄清楚如何做的事情),大问题是如果用户添加比如说另一辆福特汽车,它现在会一直显示在下拉列表的底部,它看起来会非常混乱,甚至可能被忽略,所以有什么想法吗?
ps 将 jquery 添加到标签中,以防这是一个可能的解决方案,因为我可以在这个项目中使用它。
编辑 - 对于第三列位值过滤器,这是解决方案
Problem is my selectlist might have data(plus it's format is something like [Ford IV 200 xyx]) in it which I want to retire(by only displaying records which has a bit value of true in it's 3rd column which is also something I need to figure out how to do), big problem is if the user adds in say another Ford which would now display all the way at the bottom of the drop down it would look very messy and could even be overlooked so any ideas?
p.s. added jquery to the tags in case that was a possible solution to this since I am able to use that in this project.
Edit - For that 3rd column bit value filter here's the solution
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用
OrderBy
扩展方法:You could use the
OrderBy
extension method:感谢达林,我能够想出他的稍微修改过的解决方案,这反而导致我在虚拟机中解决这个问题,如下所示
thanks to Darin I was able to come up with the slightly modified solution of his which instead lead to me resolving this in the VM like so
如果您的下拉列表有编辑器模板,这将根据文本对其进行排序。
<代码>
selectList.OrderBy(x => x.Text)
In case where you have an editor template for your dropdownlist, this will sort it based on text.
selectList.OrderBy(x => x.Text)