此功能將讓您在Javascript直接將一個(gè)Html FORM 提交給一個(gè)C#方法。示例代碼如下:
C#方法
public class AjaxProduct { public int Insert(Product product) { product.EnsureItemIsOK(); return BllFactory.GetProductBLL().Insert(product); } } public sealed class Product : MyDataItem { public int ProductID { get; set; } public string ProductName { get; set; } public int CategoryID { get; set; } public string Unit { get; set; } public decimal UnitPrice { get; set; } public int Quantity { get; set; } public string Remark { get; set; } }
Javascript調(diào)用代碼
function InsertProduct(j_dialog){ $("#formCreateProduct").ajaxSubmit({ url: "/AjaxProduct.Insert.cs", success: function(responseText) { // ............ } }); }
好了,就這樣就可以了,此時(shí)JS就可以直接將當(dāng)時(shí)RORM中所有輸入提交到C#的方法,是不是很簡單?
只要一個(gè)調(diào)用$("form").ajaxSubmit()就把一個(gè)FORM提交到了C#方法,而且參數(shù)也給準(zhǔn)備好了!
說明一下:
1. ajaxSubmit() 是JQuery的一個(gè)插件jquery.form中包含的方法。
2. “JS直接調(diào)用C#方法”示例中的方法參數(shù)也可以是這樣的自定義類型,原理一模一樣。
好了,這個(gè)演示就寫到這里,更多細(xì)節(jié)請查看用戶手冊。
Fish Li (李奇峰)
浙公網(wǎng)安備 33010602011771號(hào)