html - read ASP.net mvc Drop down list in .cshtml -
i have drop downwards list populated different values depending on country user selects.
in .cshtml file create dropdown list binding enum
@helper dropdownfield(string binding, type enumtype) { <!-- ko : @(binding) --> <div class="control-group" data-bind="css: { error: isinvalid }"> <label class="control-label" for="@binding" data-bind="text: title">replace me</label> <div class="controls"> <select id="@binding" name="@binding" data-bind="value: value"> @{dictionary<string, string> enumvalues; } enumvalues = enumextensionmethods.getnameandfriendlynamedictionary(enumtype); @foreach (keyvaluepair<string, string> kvp in enumvalues) { @:<option value="@kvp.key">@(!string.isnullorwhitespace(kvp.value) ? kvp.value : " ")</option> } </select> <span class="help-inline" data-bind="text: errormessage"></span> </div> </div> <!-- /ko --> }
then code display appopriate list depending on country selected. of course of study not working. not sure of syntax can utilize check value of country.
@dropdownfield("country") if ($('#country').val() == "us") { @dropdownfield("state", typeof(statetype)) } else { @dropdownfield("state", typeof(provincetypeca)) }
maybe create js fiddle next time...
your code looks wee bit complicated (i'm not much of fan of < ! -- ko) if create dropdown had it's values chosen via country create array of countries (obviously) create sec drop downwards computable. compute store 2d array, 1 side beingness country it's , other beingness data, i.e.
[{"australia", "gday mate"}, {"australia", "more dropdown stuff!!"}, {"america", "howdy partner"}, {"paris", "baguette nice"}]
then create computed filter results depending on country selected @ time.
then when country selected computed update (because in enable field of sec dropdown set country it's enable disabled when no country chosen) , hence have date dropdown
or follow tutorials here show how ;) http://ryanrahlf.com/building-cascading-dropdowns-with-knockout-js/ --- http://ryanrahlf.com/building-cascading-dropdowns-with-knockout-js-part-2-working-with-flat-data/
not sure how because havn't done them, eye balled them , right
html asp.net model-view-controller knockout.js
No comments:
Post a Comment