日期:2014-05-17  浏览次数:20740 次

mvc2中DropDwonList修改的时候如何显示数据中的默认值
mvc2中DropDwonList修改的时候如何显示数据中的默认值?

具体:添加的时候选择的是北京,在修改的时候默认选中的就是"北京"


------解决方案--------------------
例:区域列表AreaSelectList, 区域字段AreaId
<%=Html.DropDownListFor(m => m.AreaId, Model.AreaSelectList) %>
------解决方案--------------------
你这个应该发到ASP.NET版
------解决方案--------------------
绑定的时候给他个默认值不行了。。
------解决方案--------------------

Modle:
   public class SettingsViewModel
   {
       Repository rp =new Repository();
       public string ListName { get; set; }  
       public  IEnumerable<SelectListItem> GetSelectList()
       {
               var selectList = rp.GetArea().Select(a => new SelectListItem { 
                               Text=a.AreaName,
                               Value=a.AreaId.ToString()
                               });
               return selectList;
           }
       } 
Controller:
       public ActionResult Index()
       {
           return View(new SettingsViewModel());
       }
View:
@model Mvc3Applicationtest2.Models.SettingsViewModel
@Html.DropDownListFor(m=>m.ListName,Model.GetSelectList(),"请选择")