我有一個問題與我的代碼片段內的MVC 3與Razor語法。在我的DB表(MySQL)中,我有一個柱(FK)LanguageID [int]
。然後,在視圖中,我要分配給該列與語言列表DropDownList的,我在飛行中產生:MVC 3 DropDownListFor和錯誤的值錯誤
List<SelectListItem> list = new List<SelectListItem>();
list.Add(new SelectListItem
{
Value = tableRow.ID.ToString()
,
Text = "language"
}
然後,在視圖中,我該列表連接到語言特性:
@Html.DropDownListFor(
model => model.Language,
new SelectList(ViewData["LanguageList"] as List<SelectListItem>,
"Value", "Text")
)
,但是,當我的數據發佈到服務器,它與錯誤結果"The value '353' is invalid."
其中353
從DB語言ID返回。我究竟做錯了什麼 ?
編輯 Whle調試,我注意到了的ModelState內的錯誤信息:"The parameter conversion from type 'System.String' to type 'FavorytaWeb.Models.BookLanguage' failed because no type converter can convert between these types."
這將是非常有用的發佈被稱爲(形式控制器/行動) –