SelectList 根据“退休”的 SQL 表 bool 列过滤结果
我有一个在 ViewModel 和 DropDownFor 中设置的选择列表,它本身已经排序,如下所示,但我需要它进行过滤,以便第三列“退休”(如果它的值为“0”)所有这些结果都是显示,但如果是“1”则不显示。
我想我需要在 .OrderBy(...).Where(m=>m.Retired 之后添加,但不知道如何从那里过滤它,并且不必是 中完成,但这就是我实现 OrderBy 过滤器的方式
在VM
List<Reason> reasonList = _db.Reasons.OrderBy(m=>m.Description).ToList();
ReasonList = new SelectList(reasonList, "Id", "Description");
。
<%: Html.DropDownListFor(m => m.amwrAudit.AppTherRea, Model.ReasonList, "---------------------- Select a Reason ---------------------")%>
I have a selectlist which I've setup in a ViewModel and DropDownFor and it already has itself ordered as u can see below but I need it to filter so that the 3rd column "Retired" if it's value is "0" all those results are show but not if it's "1".
I was thinking I would need to add after the .OrderBy(...).Where(m=>m.Retired but don't know how exactly I'd filter it from there and ofc it doesn't have to be done in the VM but that's just how I was able to implement the OrderBy filter.
VM
List<Reason> reasonList = _db.Reasons.OrderBy(m=>m.Description).ToList();
ReasonList = new SelectList(reasonList, "Id", "Description");
DDF
<%: Html.DropDownListFor(m => m.amwrAudit.AppTherRea, Model.ReasonList, "---------------------- Select a Reason ---------------------")%>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在寻找
.Where(m=>!m.Retired)
。因为它是布尔值,所以不需要等号。如果您对该语法感到不舒服,您仍然可以输入
.Where(m=>m.Retired == false)
Are you looking for
.Where(m=>!m.Retired)
. Because it is a bool, no equal signs are needed.If you are uncomfortable with that syntax you can still type
.Where(m=>m.Retired == false)