How to call overloaded C# function through JQuery in Asp.Net MVC 2

I am having a problem while calling overloaded C# function through jquery post method.

I have two functions in c#

string func(string a)
string func(string a, string b)

Now when i call function which has one parameter in jquery like this

var url = '<%= Url.Action("func", "Team") %>';                
$.post(url, { a: "test" }, function (data) {
});

It gives me this error

The current request for action 'func' on controller type 'TeamController' is 
ambiguous between the following action methods

I want to know how can i call these overloaded functions. Im using Asp.Net MVC 2 with C#


ASP.NET MVC generally does not allow action overloads. If you want to do different things depending on content you're sending to server then you should consider seprating processing between two functions with different names (different action names and different URLs apparently). If you want to keep the overloading in code then still you should decorate those functions with [ActionName("%some_name_here%")] attributes giving them different names.

If you want to keep single action name then create a "Front-End" action with two parameters a and b and there in action code check if b==null . If b is null then call func(a) overload, otherwise call func (a,b).

链接地址: http://www.djcxy.com/p/51996.html

上一篇: 在javascript中循环遍历一个对象的所有成员

下一篇: 如何在Asp.Net MVC 2中通过JQuery调用重载的C#函数