-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Url generate problem #24288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
a note for // we are in url /blog/post/33?cate=dog&water=milk
@Url.Action()
output : /blog/post/33?cate=dot&water=milk
but
@Url.Action(new { id = 32 })
output: /blog/post/32 , this is actually be a "wrong" link,
because it drop "cate" and "milk" , write this meaning
we want to drop the "cate" and "water"
previously we need to write @Url.Action(new { id= 32, cate="", water = "" }) this will effect
|
Thanks for contacting us. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
a simple fix can be done here that add aspnetcore/src/Mvc/Mvc.Core/src/Routing/UrlHelperBase.cs Lines 307 to 339 in 7e5588b
and razor page take
and almost all current route value name is very common in querystring
we really need to find a way to change all the |
@mkArtakMSFT this issue exists so long , Will it be fix in Asp.NetCore 6 ? //frontend --- NewController
[HttpGet("/News")]
[HttpGet("/News/c-{cId:int}")]
public IActionResult Index(int cId){}
// manage end
[Area("Admin")]
public class NewsController:Controller
{
// the url is "/Admin/News/Index" by conventional routing
public IActionResult Index()
} and we you in "Admin" Area, and use |
Thanks for contacting us. |
I am having an issue with Url.Action creating incorrect links. @Url.action("Index", "UserAdmin", new { Area="Admin" }); Creates /Admin?controller=UserAdmin this is wrong with how MVC routes this should be /Admin/UserAdmin as it has done in all other version of .net. Also the system acts like that route doesn't exist when i put it in by hand to the correct url even though i have done a MapControllerRoute() app.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
); |
this is not a bug, but it should be, and if you guys still think it should be the designed behaviors please make a vote here
Describe the issue
this is my second time to report this aspnet/Mvc#7046, previously I think it may be fixed by the
Endpoint-Routing
, but it doesn't.we create the MVC which we try to separate the
View
andController
, and they both follow the contract which is theModel
,but this issue cause the View must know about the controller/action and it's routing metadata.
think follow controller:
now when you routing in the view, you must know who is the controller and where is it, if you don't, then it's wrong
because if you in area "foo" , it not point to foo area, instead it point to area null so it will be
/blog/1-0
,if you in area "null" , then it also point to
/blog/1-0
, but if you in/blog/5-3
it will be/blog/1-3
so how can your view know where it is ? so, to correct the link you need to writeTo Reproduce
https://github.com/John0King/UrlGenTest it's the old repo , but it explain everything
what cause it
{controller=Home}/{action=Index}/{id?}
map to "HomeController.Index" with[Route("/")][Route("[controller]/[action]/["id"]")]
) others with[Route("[controller]/[action]/{id?}")]
(the endpoint route-data) on the action , but this one is not the main issue, it the attribute routing with higher priority is OK for this issue, it's jut will some api override the MVC 's path (because api normally we hard code it's api path like/api/foo/getlist
instead of generate it )endpoint
, it cause our view must know about the action's routing datahow to fix
the Attribute-Routing already give us answer to know what kind of routing data need to keep, for example
[controller]/[action]/{id}
thecontroller
andaction
will be keep andid
will be drop for[area]/[controller]/[action]/{a}/{b}
thea
andb
will be drop, the route value with[ ]
is called framework route variables, when you write the view, the view must know those variables but it do not know the route variables with{ }
, here is the framework route variables https://github.com/John0King/UrlGenTest/blob/8f4ad7aa6ae9c5552845a0fd27100149c63e00b1/Views/Shared/NewsTest.cshtml#L91-L96we need to let the
IUrlHelper
to know theActionContext.ActionDescriptor.RouteValues
and keep all the route value if we do not override it we can usestring.Empty
to override the empty "area" route datais there a break change after fix
theoretically yes, but actually no. because if your app has correct link , then the link must be correct : for example
case 1:
Non-area has attribute route, and area has conventional route , you must add area so the link in area is correct, and if someone want to goto non-area, then the empty area must be set so it can make conventional route to conventional route to work.
case 2:
from area to non-area with
null
, it won't work even now, because null is the default value ofRouteContext
, so it must usestring.Empty
, and it will work after the change too.case 3:
same page route like
{a}-{b}
, to make link link correct , you must specific botha
andb
to make the link corrent, otherwise even developer can not know what link it will be eg for route{a}-0
/0-{b}
/{a}-{b}
, if you ignorea
then click a link withb=1
then link maybe/0-1
or22-1
or{any}-1
so no one will ignore any of themFurther technical details
The text was updated successfully, but these errors were encountered: