Open Dunge opened 3 years ago
@Dunge Can you confirm how you are instantiating an urlHelper Instance?
Hello @sackri10 thanks for the reply.
In my original post I was using in inside an IHtmlHelper extension so I did it this way:
var urlHelperFactory = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IUrlHelperFactory>();
var urlHelper = urlHelperFactory.GetUrlHelper(helper.ViewContext);
But since then I tested by creating a new empty project doing just that to be sure there was nothing else was interfering, and used it directly using @Url
inside a .cshtml view. It produced the exact same results.
@Dunge
If you have the GitHub URL for the test project, can you please add it here?
Here you go:
https://github.com/Dunge/UrlHelperFailure
This is the Visual Studio 2019 MVC template with just the default route changed and the Test Controller/View as above.
Access via https://localhost:5001/Test/Test to see the result.
@javiercn can you please take a look at this? Thanks!
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.
I have a ASP.NET Core MVC .NET5 application with a simple route. It is the default controller/action pattern with an optional integer parameter. It is configured as:
endpoints.MapControllerRoute("default", "{controller=Account}/{action=Login}/{enterpriseId:int?}");
And a test Controller with two actions, one without query string parameters, one with one:
I can access the site via those URL successfully:
The versions without the /1 doesn't contains a RouteData entry for enterpriseId value, the others do, which is fine.
When using UrlHelper.Action(), the parameter "values" allow to pass both Route data entries and query strings. But somehow it fails to resolve when setting the RouteData entry to null only in the specific case that it also contains query parameters.
I would expect the last line to also returns "/Test/TestQuery?test=2" instead of null.
Why does the sixth line behave differently than the third one (both with enterpriseId set to null)? But it works when it is omitted? Why can't it resolve to the URL I expect?
Is this a bug in the framework or something I misunderstand?
Worth mentioning that in the previous ASP.NET version (non-Core), using UrlHelper.GenerateUrl() was working fine with all cases.