0

Using ASP.NET MVC 4 I have two Index method in the same controller but with different signatures.

    public ActionResult Index()
    {
        //...
    }

    public ActionResult Index(ManageOvertimesViewModel model)
    {
        //...
    }

I don't understand why am I getting this error. (If I give a HttpPost attribute than it work so probably I will do, but I don't understand why it is not working.)

dvjanm
  • 2,351
  • 1
  • 28
  • 42
  • possible duplicate of [How can I avoid AmbiguousMatchException between two controller actions?](http://stackoverflow.com/questions/732205/how-can-i-avoid-ambiguousmatchexception-between-two-controller-actions) – twoleggedhorse Oct 11 '13 at 14:16
  • @twoleggedhorse: I know that it could be solved, but I am interesting in Why the framework can not decide which to call based on http parameters. – dvjanm Oct 11 '13 at 14:33

1 Answers1

0

I think, you can't have 2 ActionResult responding to the same HTTP Operation mainly because:

What action would the framework choose if you get a HTTP GET with empty parameters? the first (with no model bind) or the second one (with an empty model bind)? based just on parameters is not that easy if you really think about it, it could lead to undesired results.

JOBG
  • 4,544
  • 4
  • 26
  • 47
  • Yes, probably this can be the reason so I accept it, but it works the same way if I have two Index and the first has no parameter, the second has a value-typed parameter which can't be null. – dvjanm Oct 11 '13 at 15:08
  • Are you doing modifications on the second Index action? if not maybe you just need one Index Action with the model (assuming its for filtering and the logic does not differ much) – JOBG Oct 11 '13 at 15:17