ASP.NET MVC Actions Overload

How can I overload actions in ASP.NET MVC, but with GET QueryString support? I tried to do something like this:

public JsonResult Find(string q)
{
    ...
}

public JsonResult Find(string q, bool isBlaBla)
{
    ...
}

But whenever I turn to /controller/find?q=abcor /controller/find?q=abc&isBlaBla=false, it gives out System.Reflection.AmbiguousMatchException.

How to fix it?

+5
source share
3 answers

You really don't need to create overloads. All you have to do is create a single action method with all the possible arguments you expect and display the values ​​(where possible) for you.

public JsonResult Find(string q, bool isBlaBla)
{

}

You can even use optional parameters and name arguments if you are using C # 4.0

+2
source

ASP.NET HTTP-.

+1

, . find/abc find/abc/false

if you must use the query string, you can use arguments without arguments and access the button HttpContext

0
source

All Articles