在活动项目列表中显示不活动的选定项目 [英] showing inactive selected item in active item list

查看:67
本文介绍了在活动项目列表中显示不活动的选定项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下拉框,仅显示列表中的活动项目。但是用户可能已经选择了一个项目并保存了,后来同一项目可能处于非活动状态。用户编辑其选择时。他们先前选择的非活动项目应与其他活动项目一起成为编辑页面上列表中的默认项目。我不确定如何检查。这是填充我的列表的代码。

I have a dropdown box which only shows active items in the list. But a user might have selected an item and saved and later that same item might be inactive. When the user edits their selection. The inactive item they have previously selected should be the default item in the list on the edit page along with other active items. I am not sure how to check for that. Here is my code which populates my list.

var meetingTypes = _meetingTypeRepository.FindAll().OrderBy(m => m.Description);
viewModel.MeetingTypes = meetingTypes.Where(a=> a.IsActive ?? false)
                                     .ToSelectList("MeetingTypeId", 
                                                   "Description",                
                                              viewModel.MeetingTypeId.ToString());


推荐答案

我能够弄清楚,以防万一这个人碰巧也有同样的情况。由于我使用的viewModel具有所有需要比较的项目ID,因此我在Where子句中使用了它,这就是我的where子句更改为的方式:

I was able to figure it out just in case another person happened to have the same situation. Since i was using a viewModel which has all the item id's that i needed to compare against i used this in my Where clause and this is how my where clause changed to:

.Where(a=>a.IsActive == true || a.MeetingTypeId == viewModel.MeetingTypeId)

这使我可以在下拉列表中显示用户先前选择的项目,即使该项目当前处于非活动状态。

This allowed me to display the previously selected item by the user in the dropdown list even if that item is currently inactive.

这篇关于在活动项目列表中显示不活动的选定项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆