我想基於另一個組合框的選擇填充一個組合框的值。我在MVC 5應用程序中使用kendo mvc組合框。在我的情況下,我試圖根據SalesOrganisation組合框的選擇填充銷售辦公室組合框。爲了做到這一點,我需要調用SalesOffice組合框的控制器方法並傳遞國家/地區代碼值。我已經在銷售組織的下拉控件的變更事件上編寫了一個ajax方法。它調用控制器方法。我可以看到方法觸發,但是當我對JavaScript代碼中的數據做出警報時,值顯示[object] [object]。但狀態顯示成功不知道什麼是錯誤的。我如何得到填充售樓處下拉基於另一個kendo combobox填充劍道MVC組合框
組合框
<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控制器方法
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);
}
});
}
有你看了這個例子怎麼辦級聯組合的http://demos.telerik。com/kendo-ui/combobox/cascadingcombobox –
你已經共享的例子是使用odata。在我的代碼中,我試圖調用被觸發的控制器操作方法。我可以看到它在服務器端獲取數據。我的問題是如何獲取客戶端上的json數據並綁定它 – Tom
如果這是獲取組合框列表中的值,或者它拉回一個新的「select」列表來綁定到組合框? –