2014-04-05 5 views
0
다음과 같이 내가

DropDownList.Optgroup.MVC 패스 선정 값

내 코드입니다 (< OPTGROUP MVC에서 > 태그 도우미 클래스)는 DDL DropDownList.Optgroup.MVC을 사용하고

:

MvcApplication1.Models.Database1Context db = new MvcApplication1.Models.Database1Context(); 
    var data = db.locations.ToList().Select(t => new GroupedSelectListItem 
    { 
     GroupKey = t.location_group_id.ToString(), 
     GroupName = t.location_group.name, 
     Text = t.name, 
     Value = t.id.ToString() 
    }); 

선택한 값을 전달하는 방법이 표시되지 않습니까? (이 경우 선택한 위치)

위와 같이 데이터베이스 컨텍스트를 사용하는 동안 어떻게 처리해야합니까?

답변

0

var data = db.locations.ToList().Select(t => new GroupedSelectListItem 
     { 
      GroupKey = t.location_group_id.ToString(), 
      GroupName = t.location_group.name, 
      Text = t.name, 
      Value = t.id.ToString(), 
      Selected= t.Id == 1;//specify condition you want. 
     }); 
+0

내가 같은 시도하려고하지만, 작동하지 않는 :( –