C
C#2y ago
M B V R K

How to access to the 'Index' Action without write it after slash

Hello dear friends, I'm working on Asp.Net Core 6 project with Areas, I have a problem with routing to the index action. The problem: Let's assume that I have a Controller called SchoolSubjectController, and it contains an Action result called Index. Above the Controller I apply a set of Attributes as shown bellow
#region Filters

[ExceptionHandlerFilter]

#endregion
[Area( nameof(AppUserRole.Admin))]
[Route( nameof(AppUserRole.Admin) + "/[controller]/[action]")]
[Authorize( Roles = nameof(AppUserRole.Admin))]
public class SchoolSubjectController : Controller
{
public async Task<IActionResult> Index()
{
// Sme logic here
return View( model );
}
}
#region Filters

[ExceptionHandlerFilter]

#endregion
[Area( nameof(AppUserRole.Admin))]
[Route( nameof(AppUserRole.Admin) + "/[controller]/[action]")]
[Authorize( Roles = nameof(AppUserRole.Admin))]
public class SchoolSubjectController : Controller
{
public async Task<IActionResult> Index()
{
// Sme logic here
return View( model );
}
}
From the browser when I try to access to the Index action I should write .../Admin/SchoolSubject/Index. The question: Please is there any method to let the Index action is the default to show when I access to .../Admin/SchoolSubject, in other means how to access to that Index Action without write it after the controller's name in route ? Massive thanks in advance.
5 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
M B V R K
M B V R K2y ago
above the Index ?
Instinct
Instinct2y ago
Or don't include the action in the controller route
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
M B V R K
M B V R K2y ago
I tried this but didn't work But when I tried this
[HttpGet("/[area]/[controller]")]
[HttpGet("/[area]/[controller]")]
It works