2014-09-23 145 views
0

在我的Asp.Net MVC項目中,我有兩個下拉列表。我的看法(剃鬚刀)看起來像:Asp.Net Mvc隱藏下拉列表

 @{ 
       string birth_Date = null; 
       @Html.DropDownListFor(model => model.Birth_Date, 
       new SelectList((System.Collections.IEnumerable)DoctorDatawarehouse.Business.CommonChoiceList.LoadYearList(), "Value", "Text", birth_Date)) 
     } 

     @{ 
      string temp_birth_date = null; 
      @Html.DropDownListFor(model => model.Town, 
      new SelectList((System.Collections.IEnumerable)DoctorDatawarehouse.Business.CommonChoiceList.LoadEstimatedYear(), "Value", "Text", temp_birth_date)) 
     } 

我想只顯示一個下拉。如果我沒有從第一個下拉列表中選擇,我想顯示第二個下拉列表,我想隱藏第一個下拉列表。

謝謝你這麼多

+0

你能不能說清楚?首先,從不選擇/選擇第一個下拉菜單。所以它會一直顯示第二個下拉菜單。 – mrsrizan 2014-09-23 08:03:32

+0

您應該至少指定您正在編程的語言......是C#嗎? 。淨?紅寶石?視覺渦輪超Z + +親? – AJPerez 2014-09-23 08:06:02

+0

您可以放置​​複選框並切換下拉列表的可見性。那有意義嗎? – mrsrizan 2014-09-23 08:06:43

回答

0

屬性

bool IsSelected { get; set; } 

添加到您的模型或viewbag並在您查看使用

@If (model.IsSelected) // @If(ViewBag.IsSelected) 
{ 
    ... first drop down list 
} 
else 
{ 
    .... second drop down list 
} 
+0

首先非常感謝你, 我還有一個問題, 在我的模型中,我將表映射到我的db表中。但isState字段不存在。我如何添加一個屬性映射模型? – Bilal 2014-09-23 10:54:02

+0

@Bilal:'IsState'代表'IsSelected'?我將在您的控制器中使用帶有列表數據和IsSelected屬性的ViewModel。參見例如http://stackoverflow.com/a/11074506/2707156 ViewModels – StefanG 2014-09-23 11:40:33

+0

首先非常感謝你,我還有一個問題。在我的Asp.Net MVC項目中,我有一個下拉列表。我查看(剃刀)看起來:「​​

* @{ string birth_Date = null; @Html.DropDownListFor(model => model.Birth_Date, new SelectList((System.Collections.IEnumerable)DoctorDatawarehouse.Business.CommonChoiceList.LoadYearList(), "Value", "Text", birth_Date, new { @onchange = "Show()" })) }
」 – Bilal 2014-09-24 04:17:28