3
votes

Inside my asp.net mvc4 controller I have two action methods

public ActionResult Projects()

and

public ActionResult Projects(string s)

on debugging when I'm send string to this second method I'm getting error that current request is ambiguous between this two methods.

Why is that, since those have different method signature?

3

3 Answers

5
votes

MVC it cannot support two actions with the same name... even with differents signatures. The only exception is when one of the actions is decorated with a different verb attribute, like [HttpPost].

If HttpPost is not suitable for you... you need to change the action name.

Just checking around, there are some alternatives to help you having 2 actions with the same name: https://stackoverflow.com/a/1045616/7720

4
votes

Decorate them with verbs, They have different function signature but most important they have same ActionName

[HttpGet]
public ActionResult Projects()


[HttpPost]
public ActionResult Projects(string s)

Or Change the action name of one of these mehod

1
votes

String is nullable type.

So your route will match both methods for optional.

In your case below are valid

/Home/Projects/

/Home/Projects/Business/

So decorate with different name

 public ActionResult ProjectBySting(string s)

or verb like [HttpPost]/[HttpGet]