2011-12-09 5 views
2

mvc3 C#에서 백 오피스를 구현 중이며 "ComingSoon, Out, Showing"필드가있는 드롭 다운 목록의 필드를 갖고 싶습니다. 이 입력란은 어떤 수업에도 속하지 않습니다. 도우미 클래스를 만들어야합니까? 난 다음드롭 다운 목록 만들기 C# mvc3

<% List<string> foo = new List<string>(); 
    foo.Add("Showing"); 
    foo.Add("ComingSoon);" 
    foo.Add("Out"); 

    Html.DropDownList(foo, Model.Status); %> 

상태를 업데이트해야하는 DB의 필드입니다 노력했다.

답변

4
Html.DropDownList("Status", 
    new SelectListItem[]{ new SelectListItem{ Text= "Showing", Value="Showing"}, 
    //same for others 
}); 
0

이렇게하면 드롭 다운 목록을 만들 수 있습니다. 당신이 바인딩 모델을 사용하고 있기 때문에

@{   
    List<KeyValuePair<int, string>> dropdownList = 
                 new List<KeyValuePair<int, string>>(); 
       dropdownList.Add(new KeyValuePair<int, string>(0,"Showing")); 
       dropdownList.Add(new KeyValuePair<int, string>(1,"ComingSoon")); 
       dropdownList.Add(new KeyValuePair<int, string>(2,"Out")); 
       SelectList selectList = new SelectList(dropdownList, "key", "value", 0); 

} 

@Html.DropDownList("foo", selectList) 
1

, 내가 좋을 것 :

<%: Html.DropDownListFor(model=> model.Status, 
         new List<SelectListItem>() { 
           new SelectListItem{ Text= "Showing", Value="Showing"}, 
           new SelectListItem{ Text= "ComingSoon", Value="ComingSoon"}, 
           new SelectListItem{ Text= "Out", Value="Out"} 
         }); %> 

이 modelbinding를 들어, 항상 끝에서 '의 경우'와 사람을 사용, 그것은 + 사후 방법 쉽게 이름이 없으면 피드백을받습니다.