我聲明如下的ObjectDataSource
:錯誤通過的ObjectDataSource傳遞ListItemCollection到定製適配器
<asp:ObjectDataSource ID="PaymentsDataSource"
runat="server"
DataObjectTypeName="Payment"
TypeName="PaymentAdapter"
SelectMethod="GetPayments">
<SelectParameters>
<asp:ControlParameter ControlID="StartDate"
PropertyName="Text"
Name="startDate"
Type="DateTime" />
<asp:ControlParameter ControlID="EndDate"
PropertyName="Text"
Name="endDate"
Type="DateTime" />
<asp:ControlParameter ControlID="LocationCodes"
PropertyName="Items"
Name="selectedLocationCodes"
Type="Object" />
</SelectParameters>
</asp:ObjectDataSource>
控制是問題被聲明LocationCodes
這樣的:
<select id="LocationCodes"
disabled="disabled"
runat="server"
class="chzn-container"
multiple=""
data-placeholder="Choose a Location Code(s)"
style="width: 100%;"
data-class="span10">
</select>
服務器側Select
方法上適配器是這樣定義的:
[DataObjectMethod(DataObjectMethodType.Select, true)]
public List<Payment> GetPayments(
DateTime startDate,
DateTime endDate,
object selectedLocationCodes)
{
}
現在,即使ListItemCollection
成功地傳遞到Select
方法,並在Select
方法的代碼沒有錯誤可以處理,仍在被動地Application_Error
拋出下面的錯誤。有沒有辦法忽略這個錯誤?
11/15/2012 13:37:49 168 (Machine=, App=34a846f1, Project=null, Dept=null, Thread=007, TraceLevel=1)
Exception Source: mscorlib
Exception Type: System.Runtime.Serialization.SerializationException
Exception Message: Type 'System.Web.UI.WebControls.ListItemCollection' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.