Hi
i dont want to use the conventional routing pattern, insted i want to use only the attribute routing what whould happen if i used the MapController() and use views in controller (note: i know that it dose not support views and that the attribute routing is for api only )
or its better to use both convintional and attribute without use the MapController()

Aman GuptaPosted Sep 28, 2024, 2:48 PM
Hi Mina,
If you use only attribute routing in a .NET application and avoid conventional routing, while also using the
MapController()method, there are a few key points to consider:1. Attribute Routing in API vs MVC:
[Route],[HttpGet],[HttpPost], and other HTTP method attributes in MVC controllers, and they will work just fine.MapControllerRoute()(conventional routing) is typically used to map views in traditional MVC applications, whileMapControllers()is commonly used with APIs.2. What Happens When Using
MapControllers()in MVC:MapControllers()maps controllers via attribute routing only, without requiring conventional routing definitions. However, this approach was primarily designed for APIs and does not provide out-of-the-box support for returning views.MapControllers()in a typical MVC app that serves views, the routing still works, but you must rely exclusively on attribute routing. Any action method that returns a view (e.g.,return View()) will still work as long as it is correctly mapped via attributes.3. Benefits and Drawbacks:
Benefits of Attribute Routing Only:
Drawbacks of Attribute Routing Only:
4. Best Practice:
/Controller/Action/Idpattern), as it provides a simple and scalable solution.Suggested Approach:
MapControllerRoute().Example Setup with Both:
This way, you get the flexibility of custom attribute routing while keeping conventional routing for views, which simplifies maintenance and avoids unnecessary route definitions.