0

In my Asp.Net MVC project I have two dropdownlist. My View (razor) looks as:

       @{
                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))
        }

I want to show only one drop down. If i didn't choose from first drop down list, i want to show the second drop down list and I want to do hide the first.

Thank you so much

StefanG
  • 1,234
  • 2
  • 22
  • 46
Bilal
  • 159
  • 1
  • 3
  • 11
  • Can you make it clear? Firstly, first dropdown is never selected/chosen. So it will always show second dropdown. – mrsrizan Sep 23 '14 at 08:03
  • You should specify at least in which language you're programming... Is that C#? .net? ruby? visual turbo ultra Z++ pro? – AJPerez Sep 23 '14 at 08:06
  • You can put a check box and toggle visibility of dropdowns. does that make sense? – mrsrizan Sep 23 '14 at 08:06

1 Answers1

0

Add a property

bool IsSelected { get; set; }

to your model or viewbag and in your View use

@If (model.IsSelected) // @If(ViewBag.IsSelected)
{
    ... first drop down list
}
else
{
    .... second drop down list
}
StefanG
  • 1,234
  • 2
  • 22
  • 46
  • first of all thank you very much, i have one more question too, in my model i mapped table to a table from my db. But isState field doesn't exist. How can i add a property to mapped model? – Bilal Sep 23 '14 at 10:54
  • @Bilal: With 'IsState' you mean 'IsSelected'? I would use a ViewModel with your list data and the IsSelected property, that is set in your controller. See e.g.http://stackoverflow.com/a/11074506/2707156 for ViewModels – StefanG Sep 23 '14 at 11:40
  • Firstly thank you so much, I have one more question too. In my Asp.Net MVC project I have a dropdownlist. My View (razor) looks as: '
    * @{ 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 Sep 24 '14 at 04:17
  • there is a function for my dropdownlist which name is Show(), look as: ''. but i can't run this function. Where is the mistake in code? – Bilal Sep 24 '14 at 04:20