2016-04-18 41 views
0

的兩個實例我已經在模型中定義了兩個字段屬性:public bool? Afield {get;組; },公共布爾? Bfield {get;組; }。 在我看來,我使用Razor來使用dropdownlist來爲Afield和Bfield定義可能的值。問題是,當在Afield下拉列表中選擇某個值時,如何在Bfield中顯示某些值:例如:如果Afield爲A,則Bfield將僅顯示並允許選擇1,2,3以查找可能的選項。當遠處是B,那麼Bfield將只顯示並允許3,4 ... 代碼視圖: 更遠:DropDownListFor

@Html.DropDownListFor(Model => Model.Afield, new[] { 
      new SelectListItem() {Text = "A", 
       Value = bool.TrueString}, 
      new SelectListItem() {Text = "B", 
       Value = bool.TrueString}, 
      new SelectListItem() {Text = "C", 
       Value = bool.TrueString} 
     }, "Choose Afield") 

Bfield

@Html.DropDownListFor(Model => Model.Bfield, new[] { 
      new SelectListItem() {Text = "1", 
       Value = bool.TrueString}, 
      new SelectListItem() {Text = "2", 
       Value = bool.TrueString}, 
      new SelectListItem() {Text = "3", 
       Value = bool.TrueString} 
     }, "Choose Bfield") 

如果需要以其他方式處理,請提出建議。

回答