SelectList 根据“退休”的 SQL 表 bool 列过滤结果

发布于 2024-10-14 22:54:48 字数 588 浏览 1 评论 0原文

我有一个在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅听莫相离 2024-10-21 22:54:48

您是否在寻找

.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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文