我一直在處理與我能夠填充,但如果我回來編輯記錄,下拉列表不顯示所選值下拉列表.....ASP.Net MVC下拉列表中選擇價值
在控制器,
var datacontext = new ServicesDataContext();
var serviceToUpdate = datacontext.Mapings.First(m => m.CustomerServiceMappingID == id);
var qw = (from m in datacontext.Mapings
where id == m.CustomerServiceMappingID
select m.CustomerID).First();
ViewData["CustomerID"] = qw;
int b = Convert.ToInt32(serviceToUpdate.ServiceID);
var a = datacontext.services.Select(arg => arg.ServiceID).ToList();
ViewData["ServiceID"] = new SelectList(a,serviceToUpdate.ServiceID);
鑑於:
@Html.DropDownListFor(model => model.ServiceID, ViewData["ServiceID"] as SelectList)
serviceToUpdate,服務ID具有正確的值,但不知何故,當我嘗試編輯沒有返回所選值...相反下拉列表的第一個值只返回...
嘿,我正在從數據庫中得到結果..所以,你認爲null模式是可能的嗎? – 2011-06-10 06:40:20
如果結果爲空,則將所選項目設置爲空對象 – 2011-06-10 06:42:19
結果永遠不會爲空。所選值被提取並且正確無誤當我點擊編輯時它不顯示選定值 – 2011-06-10 06:43:55