同樣是呼叫第三方 web service 時碰到的狀況:Visual Studio 產生的 proxy 類別的每個屬性名稱後面都多加了 "Field",例如:CustomerIdField、CompanyField 等等。先說解法:在定義 WCF 服務的介面時,為每個介面方法套用 XmlSerializeFormatAttribute 就行了。
(以下是細節描述,純粹記錄,除非你也碰到同樣問題,否則無須細讀。...
DropDownList problems : The ViewData item that has the key 'X' is of type 'Y' but must be of type 'IEnumerable<SelectListItem>'.
反覆查看程式碼,並沒有發現錯誤訊息中描述的傳錯物件類型的問題。原來是 POST 時發生欄位驗證失敗,於是在伺服器端的 Controller 中走的路徑並未建立 DropDownList 所需要的 ViewData 所致。
這個錯誤訊息還真有點讓人摸不著頭腦。記一下!
參考資料
http://forums.asp.net/t/1562501.aspx/2/10...