开发者

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

开发者 https://www.devze.com 2023-02-07 20:41 出处:网络
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 \

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


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)

0

精彩评论

暂无评论...
验证码 换一张
取 消