asp.net mvc 3 - MVC3 DropDownList + JSON + selected issue -
i have strange behaviour between website (mvc3 + jquery) , mobile version (mvc3 + jquery mobile) split in 2 distinct solutions.
i using following code change concent of dropdown (searchvalue) according 1 (searchby).
razor:
@html.dropdownlistfor(x => x.selectedsearch, new selectlist(model.searchby, "key", "value"), new { onchange = "getvalues($(this).val());" }) @html.dropdownlistfor(m => m.selectedsearchvalue, new selectlist(model.searchvalue, "key", "value"))
json:
$.ajax({ type: "post", url: '@url.action("getvalues", "search")', data: "{searchid:" + searchid + "}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (data) { var options = $('#selectedsearchvalue'); $('option', options).remove(); // remove previous $.each(data, function () { options.append($('<option/>').val(this.id).text(this.display)); }); } });
this code working fine on website (jquery) not case on mobile website (jquery mobile) working opera mobile not ff or ie or safari ... (i tried user agent simulate mobile devices)
the values of searchvalue dropdown correctly set @ end of json call, selected value previous selected value (which not in possible values of dropdown). not sure clear give little example :
i have following possibilities searchby: - name - car
when select name, display in searchvalue "name1", "name2", etc etc , when select car, display in searchvalue "car1", "car2", etc etc
but previous code on mobile website, when change value "name" car", dropdownlist correctly refilled right values ("car1", "car2", etc) selected value previous 1 (e.g. "name1") if not in possible values of dropdown. try select manually first value nothing happens :
$('option[value=' + mybeautifulvalue + ']').attr('selected', 'selected');
do have idea fix problem? doing wrong?
thank in advance help, nico
ps: sorry poor english
ok, found solution. have refresh dropdown, wierd! :
var myselect = $("#selectedsearchvalue"); myselect[0].selectedindex = 0; myselect.selectmenu('refresh');
Comments
Post a Comment