I have coded a C# MVC5 Internet application and have a question about two ActionResult methods in the same controller.
I have two Index ActionResult methods as follows:
public async Task<ActionResult> Index()
public async Task<ActionResult> Index(int? mapCompanyId)
I am wanting to browse to either the Index() method or the Index(int? mapCompanyId) method, depending on if a value is specified for the mapCompanyId.
Currently, I am getting this error:
The current request for action 'Index' on controller type 'MapLocationController' is ambiguous between the following action methods:
System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult] Index() on type CanFindLocation.Controllers.MapLocationController
System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult] Index(System.Nullable`1[System.Int32]) on type CanFindLocation.Controllers.MapLocationController
I can rewrite my code so that there is only one Index ActionResult, but would rather have two if possible.
Is it possible to have two ActionResults with the same name, and depending on if a value is specified, the relevant ActionResult is executed. If so, is it easy to implement, or is it not worth the time?