Using Attribute Routing (Route Attribute), I have two action methods with same name in two different controllers as follows
public class HomeController : Controller
{
//URL: /accessMethod
[Route(“accessMethod”)]
public ActionResult Method1()
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
}
public class AccountController : Controller
{
//URL: /accessMethod
[Route(“accessMethod”)]
public ActionResult Method2()
ViewBag.Message = "Welcome to ASP.NET MVC!";
return View();
}
}
while hitting the url http://localhost:1234/accessmethod, the following error occurred
Server Error in '/' Application.
Multiple controller types were found that match the URL. This can happen if attribute routes on multiple controllers match the requested URL.
The request has found the following matching controller types: mvc_Test.Controllers.Page1Controller mvc_Test.Controllers.Page2Controller
Requesting you, How to resolve this issue without using RoutePrefix Attribute? Instead RoutePrefix, we can use Controller name right? Then what is the main use of Attribute Routing?