I'm using attribute routing in my MVC5 application and it is working fine. When I tried to create an area and placed attribute routing on the controller inside it, it returns 404.
I know, to enable attribute routing inside Area, I have to use [RouteArea("Area Name Here")]
and also have to add routes.MapMvcAttributeRoutes();
inside my RouteConfig class. I did all this and designed my controller like this:
[RouteArea("Client")]
[RoutePrefix("Client")]
public class ClientController : Controller
{
#region Properties
private readonly string apiUrl = ConfigurationManager.AppSettings["apiUrl"];
#endregion
#region Constructor
public ClientController()
{
}
#endregion
#region Action Methods
[HttpGet, Route("create")]
public ActionResult Index()
{
--logic here
}
#endregion
}
When i run the application using the route: http://localhost:26189/Client/create
, I'm able to hit the constructor but not the Index method. Interestingly, if i remove the attribute [HttpGet, Route("create")]
and try this route http://localhost:26189/Client/Index
it will hit the Index method.
I'm going through these links but not found the exact fix: https://blogs.msdn.microsoft.com/webdev/2013/10/17/attribute-routing-in-asp-net-mvc-5/#route-areas
[ActionName("create")]
for index action. – Amit