This works。可能有點慢,但我不在乎:
public static class SelectListExtensions{
public static SelectList Without
(this SelectList selectList, params int[] what){
var items=selectList.Items.Cast<dynamic>()
.Where(x=>!what.Any(z=>x.Value==z));
return new SelectList(items);
}
public static SelectList Without<T>
(this SelectList selectList,params T[] what) where T:Enumeration{
var items=selectList.Items.Cast<dynamic>()
.Where(x=>!what.Any(z=>x.Value==z.Value));
return new SelectList(items);
}
}
更好的方法是值得歡迎的。
沒有。這是行不通的。呈現的Html:
<select data-val="true" data-val-required="The JMC decision field is required."
id="JMCDecisionStatus" name="JMCDecisionStatus">
<option>{ Name = Successful, Value = 2 }</option>
<option>{ Name = Reserved, Value = 3 }</option>
<option>{ Name = Rejected, Value = 4 }</option>
</select>
不完全是我在找什麼。 :D
您可以擴展您的方法不工作的哪一點? – 2011-03-14 09:29:34
@Mark'selectList.Items.Where(x => x.Value!= val)'因爲Items.GetType == typeof(IEnumerable)' – 2011-03-14 09:32:29