DropDownList: ViewData item that has the key X is of type Y but must be Z

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?DropDownList+problems+The+ViewData+item+that+has+the+key+userTYPE_id_user_type+is+of+type+System+Int32+but+must+be+of+type+IEnumerable+lt+SelectListItem+gt+
Copyright © 2012. Huan-Lin 學習筆記 - All Rights Reserved
Powered by Blogger
Template Design by Cool Blogger Tutorials
Published by Templates Doctor