SelectList to filter results based on sql tables bool column for “Retired”

孤人 提交于 2020-01-03 03:44:08

问题


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 ---------------------")%>

回答1:


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)



来源:https://stackoverflow.com/questions/4831092/selectlist-to-filter-results-based-on-sql-tables-bool-column-for-retired

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!