1
我是Kendo UI的新手,我有一個網格,我從JSON格式的asmx webservice填充,它顯示數據正常。我已經啓用了編輯功能,但是當我點擊更新按鈕時沒有任何反應,我沒有進入我的web方法的斷點。Kendo UI網格不調用web服務
下面是相關的代碼snipets。 感謝
//references
<link href="Content/kendo/2012.3.1114/kendo.common.min.css" rel="Stylesheet" />
<link href="Content/kendo/2012.3.1114/kendo.default.min.css" rel="Stylesheet" />
<script src="Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script src="Scripts/kendo/2012.3.1114/kendo.web.min.js" type="text/javascript"></script>
//Data Model Classes
[Serializable]
public class Make
{
public int PhoneMakeID { get; set; }
public string PhoneMakeDesc { get; set; }
public string BillingDesc { get; set; }
}
//Web Methods
//Phone Make Get that populates the grid, works 100%
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public List<Make> GetPhoneMakes(string Active, string OfferTypeID, string TrackMonthID, string NetworkID)
{
DataTable dtPhoneMakes = new DataTable();
Microsoft.Practices.EnterpriseLibrary.Data.Database db = DatabaseFactory.CreateDatabase("PricingConnection");
DbCommand dbCommand = null;
dbCommand = db.GetStoredProcCommand("uspPS_PhoneMake_Get");
db.AddInParameter(dbCommand, "@OfferTypeID", DbType.String, OfferTypeID);
db.AddInParameter(dbCommand, "@TrackMonthID", DbType.String, TrackMonthID);
db.AddInParameter(dbCommand, "@NetworkID", DbType.String, NetworkID);
db.AddInParameter(dbCommand, "@Active", DbType.String, Active);
dtPhoneMakes = db.ExecuteDataSet(dbCommand).Tables[0];
List<Make> ml = new List<Make>();
Make m;
foreach (DataRow dr in dtPhoneMakes.Rows)
{
m = new Make();
m.PhoneMakeID = Convert.ToInt32(dr["PhoneMakeID"].ToString());
m.PhoneMakeDesc = dr["PhoneMakeDesc"].ToString();
m.BillingDesc = dr["BillingDesc"].ToString();
ml.Add(m);
}
return ml;
}
//Phone Make Update, not getting to here
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void UpdatePhoneMakes(string PhoneMakeID, string PhoneMakeDesc, string BillingDesc)
{
Microsoft.Practices.EnterpriseLibrary.Data.Database db = DatabaseFactory.CreateDatabase("PricingConnection");
DbCommand dbCommand = null;
dbCommand = db.GetStoredProcCommand("uspPS_PhoneMake_Update");
db.AddInParameter(dbCommand, "@PhoneMakeID", DbType.String, PhoneMakeID);
db.AddInParameter(dbCommand, "@PhoneMakeDesc", DbType.String, PhoneMakeDesc);
db.AddInParameter(dbCommand, "@BillingDesc", DbType.String, BillingDesc);
db.ExecuteNonQuery(dbCommand);
}
//Transports
var transpPhoneMake = {
read: function (options) {
$.ajax({
type: "POST",
url: "webmethods/phones.asmx/GetPhoneMakes",
contentType: "application/json; charset=utf-8",
data: jdPhoneMake,
dataType: 'json',
success: function (msg) {
options.success(msg);
}
});
},
update: function (options) {
url: "webmethods/phones.asmx/UpdatePhoneMakes/";
contentType: "application/json; charset=utf-8";
type: "POST";
},
parameterMap: function (data, operation) {
if (operation != "read") {
return JSON.stringify({ products: data.models })
}
else {
data = $.extend({ sort: null, filter: null }, data);
return JSON.stringify(data);
}
}
};
//DataSources
var dsPhoneMake = new kendo.data.DataSource({
transport: transpPhoneMake,
schema:
{
data: "d",
total: "d.length",
model:
{
id: "PhoneMakeID",
fields:
{
PhoneMakeID: { type: "string", editable: false, nullable: true },
PhoneMakeDesc: { type: "string", editable: true },
BillingDesc: { type: "string", editable: true }
}
}
},
pageSize: 10,
sort:
{
field: "PhoneMakeDesc",
dir: "asc"
}
});
//Grids
var gridPhoneMakes = $("#gridPhoneMakes").kendoGrid({
dataSource: dsPhoneMake,
columns:
[
{ command: ["edit", "destroy"], title: " ", width: "175px" },
{
field: "PhoneMakeID",
title: "Make ID",
filterable: false,
editable: false,
width: 75
},
{
field: "PhoneMakeDesc",
title: "Make Description",
editable: true
},
{
field: "BillingDesc",
title: "Make Code",
editable: true
}
],
toolbar: kendo.template($("#tmplPhoneMakeToolbar").html()),
selectable: "row",
sortable: true,
groupable: true,
pageable: true,
filterable: true,
autoBind: false,
editable: "inline",
batch: false
});
我相信,如果你在一個傳輸方法使用一個功能,你必須使用一個功能*所有*的方法。 –
我不是OP - 我只是指出,我不認爲你的第二個例子會爲他工作,因爲'read'已經被定義爲一個函數。 –
對不起,我誤解了這個問題,我想你在想我爲什麼認爲原文是錯的。我爲你編輯我的文章和+1。謝謝! – OnaBai