I have two dropdownlist select2 based on another. But second drownlist do not working properly in MVC4.
@Html.DropDownList("company11", ViewData["companyy"] as List<SelectListItem>,"Select",new { @class = "validate[required]" })
@Html.DropDownList("brand11", ViewData["brandss"] as List<SelectListItem>,"Select",new { @class = "validate[required]" })
This jquery code:
$("#company11").change(function () {
checkUserIdentity();
var id = $(this).val();
binddropdownn_branch(id);
});
function binddropdownn_branch(id) {
$.ajax({
type: "POST",
url: '/Product/GetbarnchList?id=' + id,
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (result) {
$("#brand11").find('option').remove();
$.each(result, function () {
var option = $("<option/>");
option.attr("value", this.Value).text(this.Text);
$('#brand11').append(option);
});
}
});
}
Kindly reply me.


Vinay SinghRank #604 · 4K reputationPosted Jun 16, 2016, 10:21 PM EDT
jQuery Ajax Cascaded DropdownList in Asp.net MVC Using C#.Net
Abhilash J ARank #1,243 · 1.4K reputationPosted Jun 16, 2016, 11:39 PM EDT
$("#brand11").find('option').remove();
$.each(result, function () {
$("#brand11").val(null).trigger("change");
var option = $("");
option.attr("value", this.Value).text(this.Text);
$('#brand11').append(option);
});
}