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

此功能将让您在Javascript直接调用当前aspx页面中的一个C#方法。示例代码如下:

C#方法

public partial class Customers : MyBasePage
{
    /// <summary>
    /// 供AJAX调用:更新客户资料。具体调用方法请参考JS代码。
    /// 方法可以是静态的,也可以是不是静态的。
    /// </summary>
    /// <param name="customer"></param>
    /// <returns></returns>
    public static int UpdateCustomerInfo(Customer customer)
    {
        customer.EnsureItemIsOK();

        return BllFactory.GetCustomerBLL().Update(customer);
    }

}

public sealed class Customer : MyDataItem
{
    public int CustomerID { get; set; }
    public string CustomerName { get; set; }
    public string ContactName { get; set; }
    public string Address { get; set; }
    public string PostalCode { get; set; }
    public string Tel { get; set; }
}

Javascript调用代码

$.ajax({
    type: "POST", 
    // 注意参数:AjaxPageMethod,它指出了要调用页面的哪个方法。
    data: $.param({ AjaxPageMethod: "UpdateCustomerInfo", CustomerID: customerId }) + "&" 
			+ $("#divCustomerInfo :text").fieldSerialize(),
    //......
});

以上功能还需要以下配置:

<httpModules>
    <clear/>
    <add name="PageMethodModule" type="FishWebLib.Ajax.PageMethodModule, FishWebLib, 
			Version=3.0.0.0, Culture=neutral, PublicKeyToken=04db02423b9ebbb2" />
</httpModules>

当上面的JS在运行时,将会把当前页面以AJAX方式提交到当前Customers.aspx页面的UpdateCustomerInfo方法中。

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

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

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

posted on   Fish Li  阅读(4418)  评论(4编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示