返回到目录:晒晒我的Ajax服务端框架

此功能将让您在Javascript直接将一个Html FORM 提交给一个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调用代码

function InsertProduct(j_dialog){
    
    $("#formCreateProduct").ajaxSubmit({
     url: "/AjaxProduct.Insert.cs",

        success: function(responseText) {
            // ............
        }
    });
}

 

好了,就这样就可以了,此时JS就可以直接将当时RORM中所有输入提交到C#的方法,是不是很简单?

只要一个调用$("form").ajaxSubmit()就把一个FORM提交到了C#方法,而且参数也给准备好了!

说明一下:

1. ajaxSubmit() 是JQuery的一个插件jquery.form中包含的方法。

2. “JS直接调用C#方法”示例中的方法参数也可以是这样的自定义类型,原理一模一样。

好了,这个演示就写到这里,更多细节请查看用户手册。

返回到目录:晒晒我的Ajax服务端框架

点击此处进入示例展示及下载页面

相关文章:

  • 2022-12-23
  • 2022-02-20
  • 2021-12-21
  • 2021-12-17
  • 2022-01-10
  • 2022-12-23
  • 2021-08-08
  • 2021-09-19
猜你喜欢
  • 2021-06-07
  • 2021-04-12
  • 2022-02-18
  • 2022-01-05
  • 2022-02-11
相关资源
相似解决方案