【发布时间】:2011-06-10 06:21:35
【问题描述】:
我一直在处理可以填充的下拉列表,但如果我回来编辑记录,下拉列表不会显示所选值.....
在控制器中,
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,ServiceID 具有正确的值,但不知何故,当我尝试编辑所选值时不返回...相反,仅返回下拉列表的第一个值...
【问题讨论】:
标签: asp.net asp.net-mvc-3