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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With