1) Add the following code under the System.Web node in Web. config
<pages controlrenderingcompatibilityversion= "4.0" clientidmode= "Autoid" >
<namespaces>
<add namespace= "Mymvc"/>
</namespaces>
</pages>
<add path= "*.cspx" verb= "*" type= "Mymvc.ajaxhandlerfactory,mymvc" validate= "true"/>
2) Add the following code to the <system.webServer> node for compatibility IIs7.0:
<validation validateintegratedmodeconfiguration= "false"/>
<security>
<requestFiltering>
<fileExtensions>
<remove fileextension= ". cspx"/>
<add fileextension= ". Cspx" allowed= "true"/>
</fileExtensions>
</requestFiltering>
</security>
<add name= "Ajaxhandlerfactory" verb= "*" Path= "*ajax*/*.cspx"
Type= "Mymvc.ajaxhandlerfactory, Mymvc" precondition= "Integratedmode"/>
The top is the configuration
For example, in AjaxMenuManager.cs, there are the following methods
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using Mymvc;
Namespace Lesso.Invoicing.UI.AjaxMethod
{
public class Ajaxmenumanager
{
[Action]
public string Test (string a)
{
return A;
}
}
}
In JS, the method is called as follows:
$.ajax ({
URL: "/lesso.invoicing.ui.ajaxmethod/ajaxmenumanager/test.cspx",
Lesso.Invoicing.UI.AjaxMethod name space; Ajaxmenumanager class name; Test method Name
Data: {A: "2"},
Success:function (responsetext) {
alert (responsetext);
},
Error:function (msg) {
Alert (msg);
}
});
It is important to note that:
The Ajax method prefixes the Ajax ...
MYMVC original article and source code: http://www.cnblogs.com/fish-li/archive/2012/02/12/2348395.html