✅ MVC application routing issue.
Why does the following code not work
But this code does
32 Replies
Because you did not specify the route
Only the parameter of that route
You need at least
asp-action
to point to the action the link supposed to link to
And maybe even asp-controller
if the controller is not the current one
The second piece of code contains all those details, so it worksIf you mean like so, the same issue persists.
I dont even get syntax highlighting with this
Huh
Show the signature of the controller and action?
Also, what .NET version?
.net 8.0
HomeController.cs
public IActionResult Details(int productId)
I assume it's a [HttpGet]
action?yes
should i put the annotation aboive it regardless?
Well, yeah?
Attributes is how you do routing
im following a course for .net mvc and he didnt do it, so i didnt do it lol
If you don't tell ASP that it's a
GET
endpoint, how is it supposed to know?Even with that, it doesnt work the way it should
huh
What HTML gets generated?
Well that's weird
yeah lol
Seems the tag helpers are not working
they are working in my other files tho
idk why its just this one
Is this view placed somewhere else than other views?
What's your
Views/_ViewImports.cshtml
file?
and its Areas/Customer/Views/Home/Index.cshtml
And the views where tag helpers work are somewhere else?
You'll need to set up separate viewimports per area
Areas/Admin/Views/ has them working
but they are setup like that
Right
are the viewimports files the same for each?
This line is important here:
yup
It's in both viewimports files?
yeah
Well, I'm at a loss then
Oh
Actually
Try adding
asp-area
as well?still nothing
ill keep bashing my head against the issue lol, been trying to solve it since early this morning xD
I decided to just manually retype all this and save...
and now it works...
syntax highlighting too
Good ol' "turn it off and back on again" never fails lmao
hopefully this fixes my issue on why my add to cart page, saves 0 to my database no matter what number i put in the input as well
yes, the tag helpers were the issue all the time, thanks for helping me so much, been at this since 9am lol, and its now 5pm xD
Anytime :Ok: