2014-09-23 147 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