MyDaftQuestions
MyDaftQuestions

Reputation: 4691

Why are these 2 methods ambiguous

I'm getting an error about my functions being ambiguous

The current request for action 'Index' on controller type 'ProductController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Index(bconn.ui.Models.Vm, Int32, Int32) on type bconn.ui.Controllers.ProductController System.Web.Mvc.ActionResult Index(System.String, System.String) on type bconn.ui.Controllers.ProductController

As you can see, one controller has the following signature

public ActionResult Index(Vm model, int startIndex, int pageSize)

And the other

public ActionResult Index(string selected, string nothing)

Due to the fact that one has int values, which are not nullable, I can't see how any ambiguity is here?

Upvotes: 1

Views: 372

Answers (1)

Omri Aharon
Omri Aharon

Reputation: 17064

It's not like in a regular class. When you have action methods, you can't overload them unless you use [HttpGet] and [HttpPost] attributes to distinguish between them.

For instance, you need to have:

[HttpGet]
public ActionResult Index(Vm model, int startIndex, int pageSize) 
{
    ...
}

And

[HttpPost]
public ActionResult Index(string selected, string nothing)
{
    ...
}

Upvotes: 3

Related Questions