ajaxPro 在vs2010 MVC下使用

本文介绍了如何在ASP.NET MVC项目中安装并使用Ajax.NET。通过详细步骤指导读者如何配置项目,包括添加引用、配置web.config文件及注册路由等。此外,还解释了如何在客户端调用服务器端的方法。
摘要由CSDN通过智能技术生成

在global中加入下句代码

routes.IgnoreRoute("ajaxpro/{*pathInfo}");

 

原帖:

Ajax.NET is the first Ajax library for the .NET framework. Up until the day ASP .NET 3.5 was released, there was nothing quite like it. In ASP .NET 2.0, the UpdatePanel was introduced as a way to enable partial rendering on ASP .NET pages. UpdatePanels are quick to implement. However, the downside of it is its inefficiency. The viewstate of the page gets posted back as well! This gives you a bloated asynchronous request and basically defeats the purpose.

It is during times like this that Ajax .NET looks very attractive. With support for PageMethods in ASP .NET 2.0 (in Ajax.NET the attribute tag [AjaxMethod] is used instead), JSON serializers, built-in caching, javascript compression, synchronous calls, etc. what is there not to like about Ajax .NET. You could even return DataTables, DataSets, enums, and other custom structures to the client-side directly.

It is also an open source project and the code is available here. Unfortunately, development of Ajax.NET has "stopped", and the creator himself has suggested the use of the Ajax features provided by ASP .NET 3.5. However, the project itself is still being updated once in awhile. I guess it's hard to completely let go of a project that you've been working on for a long time. People just get attached to their code. Well... I know I do.

Anyway, I have been using Ajax.NET since .NET 2.0, as well as since .NET 3.5. I haven't found a good reason to switch and it even runs under ASP .NET MVC and I reckon it is still better than using Ajax.ActionLink(). Unless of course, there's some easier method that I do not know of then please feel free to enlighten me anytime. Most of my Ajax use centers around requesting data from the server asynchronously and then using javascript to update the DOM.

Installing Ajax.NET

To include Ajax.NET into your MVC project, follow the following steps:

  1. Go http://ajaxpro.codeplex.com and download the latest release, i.e., 9.2.17.1 
  2. Extract AjaxPro.2.dll somewhere safe so that we can add a reference to it late in our MVC project. The other files are for the JSON serializer and for use under ASP .NET 1.1. The web.config in the zip file gives you a bunch of configurable options.
  3. Then from VS, add a reference to it in your project. 
  4. In your web.config, add the following Under <configSections>

     

       12 <sectionGroup name="ajaxNet">

       13             <section name="ajaxSettings" type="AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2" requirePermission="false" restartOnExternalChanges="true"/>

       14         </sectionGroup>


    Under <configuration>

     

       30 <ajaxNet>

       31         <ajaxSettings>

       32             <token enabled="true" sitePassword="notmypassword" />

       33         </ajaxSettings>

       34     </ajaxNet>

    Under <httpHandlers>

     

      107 <add verb="*" path="/ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>

     

  5. In global.asax, you will then need to add the following line to your RegisterRoutes() method to allow AjaxPro to handle requests directed at it.

   30 routes.IgnoreRoute("ajaxpro/{*pathInfo}");


Using Ajax.NET

To be able to call your class methods on the client-side, you will need to add the [AjaxPro.AjaxMethod] attribute to the method. The AjaxMethod attribute can be used on any methods in any classes and is not limited to methods in the code-behind of your webpages. You will then need to inform AjaxPro parse the class containing your marked method to generate proxy classes for the client-side. This usually is done via the method

 

AjaxPro.Utility.RegisterTypeForAjax(Type t)

 

at the Page class. The other method is to directlypoint AjaxPro to the location by adding the script tag

 

<script type="text/javascript" src="/ajaxpro/className,assemblyName.ashx"></script>

 

The className MUST include it's namespace. Basically the above allows AjaxPro to find the method through reflection in the assembly to generate the appropriate proxy classes.

As there is not really a concept of pages in ASP .NET MVC, the second method is used and you will additionally need to add the following script tags (these are normally generated when you use RegisterTypeForAjax)

 

<script type="text/javascript" src="/ajaxpro/prototype.ashx"></script>

<script type="text/javascript" src="/ajaxpro/core.ashx"></script>

<script type="text/javascript" src="/ajaxpro/converter.ashx"></script>

 

原帖地址:http://my6solutions.com/post/2009/03/09/Running-AjaxNET-Professional-under-ASP-NET-MVC.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值