Mvc.CascadeDropDown icon indicating copy to clipboard operation
Mvc.CascadeDropDown copied to clipboard

What if the 'First simple dropdown' has an Id

Open rasputino opened this issue 5 years ago • 0 comments

I tried this library, but if the code is like this one:

//First simple dropdown 
@Html.DropDownListFor(m=>m.SelectedCountry, Model.Countries,
"Please select a Country", new {@class="form-control", @id=$"someId_{someValue}"})

//Dropdown list for SelectedCity property that depends on selection of SelectedCountry property
@Html.CascadingDropDownListFor( 
  expression: m => m.SelectedCity, 
  triggeredByProperty: m => m.SelectedCountry,  //Parent property that trigers dropdown data loading
  url: Url.Action("GetCities", "Home"),  //Url of action that returns dropdown data
  ajaxActionParamName: "country",   //Parameter name for the selected parent value that url action receives
  optionLabel: "Please select a City", // Option label
  disabledWhenParrentNotSelected: true, //If true, disables dropdown until parrent dropdown selected
  htmlAttributes: new { @class = "form-control" }) //Html attributes

Then the first dropdown code generated loses its "Id" attribute: <select id="someId_123456789" ...

And then the javascript fails because it doesn't find the element: var triggerElement = document.getElementById('SelectedCountry');//null value

How this problem could be solved? Which is the way to set a specific Id in triggeredByProperty?

rasputino avatar May 18 '20 12:05 rasputino