C
C#3y ago
M B V R K

Routing issue with ASP.Net Core

@AspNetCore @Web Hi dear friends, I'm working on an Asp.Net core 6 project. inside a Controller called Group I have the following ActionResult
[Route( "/[area]/[controller]/Archive/Details/{id}" )]
public async Task<IActionResult> ArchiveDetails(string id)
{
var obj = await _mediator.Send( new GetGroupFromArchiveByIdQuery( id , includeDetails : true ) );
var model = _mapper.Map<GroupArchivedDetailsVm>( obj );
var statisticsData = await _mediator.Send( new GroupGetStatisticsDataQuery( id ) );

( model.AbsencesCountGroupedByMonths , model.StudentsCountGroupedByGender ) = ( statisticsData.AbsencesCountGroupedByMonths , statisticsData.StudentsCountGroupedByGender );

return View( model );
}
[Route( "/[area]/[controller]/Archive/Details/{id}" )]
public async Task<IActionResult> ArchiveDetails(string id)
{
var obj = await _mediator.Send( new GetGroupFromArchiveByIdQuery( id , includeDetails : true ) );
var model = _mapper.Map<GroupArchivedDetailsVm>( obj );
var statisticsData = await _mediator.Send( new GroupGetStatisticsDataQuery( id ) );

( model.AbsencesCountGroupedByMonths , model.StudentsCountGroupedByGender ) = ( statisticsData.AbsencesCountGroupedByMonths , statisticsData.StudentsCountGroupedByGender );

return View( model );
}
I call this action from a view of another action called Archived, and the call syntax looks like the following
<li><a asp-action="ArchiveDetails" asp-route-id="@item.Id"><em class="icon ni ni-notes"></em><span>Details</span></a></li>
<li><a asp-action="ArchiveDetails" asp-route-id="@item.Id"><em class="icon ni ni-notes"></em><span>Details</span></a></li>
The issue: When I clicked on Details button in Archived view the id looks like the break point representation screenshot attached with this question, but it should be without those % symbols like this G6-TGI - 2020/2021 Additional info: The coontroller attributes I apply on it, looks like the following
[ExceptionHandlerFilter]

[Area( nameof(AppUserRole.Admin))]
[Route( "[area]/[controller]/{action=Index}" )]
[Authorize( Roles = nameof(AppUserRole.Admin))]
public class GroupController : Controller
{
...
[ExceptionHandlerFilter]

[Area( nameof(AppUserRole.Admin))]
[Route( "[area]/[controller]/{action=Index}" )]
[Authorize( Roles = nameof(AppUserRole.Admin))]
public class GroupController : Controller
{
...
Please how do I can fix this issue? and massive thanks in advance
7 Replies
Angius
Angius3y ago
Thing is, nothing says if it's a GET route, a POST route, or what else Not sure if that's the issue, but it does strike me as odd
Saber
Saber3y ago
use a query parameter instead of a route parameter for this. asp.net doesn't decode url parameters coming into the controller
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Saber
Saber3y ago
doesn't really matter either way
undisputed world champions
or you know ... url decode it yourself?
Angius
Angius3y ago
[Route] should only really be used on the controller to specify the base for the actions. Actions should have [Http{Method}] attribute instead
M B V R K
M B V R KOP3y ago
I think by default if setting a route without [HttpPost] attribute it will be an HttpGet is I'm wrong ?

Did you find this page helpful?