I am trying to populate the value of one combo box based on selection of another combo box. I am using kendo mvc combo box in MVC 5 application. In my case , I am trying to populate the Sales Office combo box based on selection of SalesOrganisation combo box.In order to do that I would need to call the controller method of SalesOffice combo and pass the country code value. I have written a ajax method on the change event of the drop down control of the Sales Organisation. Its calling the controller method. I can see the method firing but when I do an alert on the data in the javascript code, the value is showing [object] [object].The status however is showing success Not sure what is wrong. How do I get the Sales Office dropdown populated
Combobox
<div class="form-group">
@Html.LabelFor(model => model.Company, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
@(Html.Kendo().ComboBoxFor(model => model.Company)
.Name("SalesOrganisation")
.HtmlAttributes(new { style = "width:300px" })
.DataTextField("Company")
.DataValueField("CountryCode")
.DataSource(dataSource => dataSource
.Read(read => read.Action("RequestHeader_SalesOrganisation", "Request").Type(HttpVerbs.Post))
)
.Events(e =>
{
e.Change("onChange");
})
)
</div>
@Html.ValidationMessageFor(model => model.Company, "", new { @class = "text-danger" })
</div>
</div>
<div class="clearfix"></div>
<div class="form-group">
@Html.LabelFor(model => model.SalesOffice, htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-6">
<div class="editor-field">
@(Html.Kendo().ComboBoxFor(model => model.SalesOffice)
.Name("SalesOffice")
.HtmlAttributes(new { style = "width:300px" })
.DataTextField("SalesOffice")
.DataValueField("SalesOfficeID")
.DataSource(dataSource => dataSource
.Read(read => read.Action("RequestHeader_SalesOffice", "Request").Type(HttpVerbs.Post))
)
)
</div>
@Html.ValidationMessageFor(model => model.SalesOffice, "", new { @class = "text-danger" })
</div>
</div>
SalesOffice controller method
public ActionResult RequestHeader_SalesOffice(string id)
{
var response = requestRepository.GetSalesOffice(id).AsQueryable().ProjectTo<SalesOfficeViewModel>();
var jsonResult = Json(response, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
Jquery
function onChange() {
alert($('#SalesOrganisation').val());
var ServiceUrl = "/CC.GRP.MCRequest/Request/RequestHeader_SalesOffice?id=" + $('#SalesOrganisation').val();
var content = '';
$.support.cors = true;
$.ajax({
type: 'Post',
url: ServiceUrl,
async: true,
cache: false,
crossDomain: true,
contentType: "application/json; charset=utf-8",
dataType: 'json',
error: function (xhr, err) {
},
success: function (data, status) {
$('#SalesOffice').val(data);
alert(data);
alert(status);
}
});
}