dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.38k stars 10k forks source link

Link generation improvements #38121

Open javiercn opened 2 years ago

javiercn commented 2 years ago

We have a relatively big backlog of issues with regards to link generation changes that happened between traditional routing and endpoint routing. One of the biggest changes is in the way we deal with ambient values. Changes in endpoint routing can cause some abnormal behaviors when generating links.

mkArtakMSFT commented 2 years ago

@javiercn it seems this one never got broken into individual issues prioritized. Costing the umbrella as L for now, but prioritizing the items internally could help/.

yecril71pl commented 2 years ago

Consider the following code:

services .AddRazorPages(options => options .Conventions .AddPageRoute ("/A/B", "/A/C")); 

Assume that the page /A/B exists and the page /A/C does not. in page /A/D:

<a asp-page="C" asp-route-id="0" >&hellip;</a >

Then the result is

<a href="/A/D?id=0" >&hellip;</a >

It seems the only work-around is to make C.cshtml.cs redirect to B.

valeriob commented 2 years ago

Shall i suggest to track this issue too ? https://github.com/dotnet/aspnetcore/issues/31476

Alerinos commented 2 years ago

I think it is also worth being interested in. Multi routing is sorely lacking

https://github.com/dotnet/aspnetcore/issues/37485 https://github.com/dotnet/aspnetcore/issues/39719

Alerinos commented 2 years ago

When it comes to generating links, I would recommend using the page class. Example:

Counter.razor 
@page "/Counter"

<link href="@Pages.Counter">Counter</link>

output:
<a href="/Counter">Counter</a>

This causes the content of @page to be inserted in place of href

For this you can create a provider that adds other constants, e.g. culture.

valeriob commented 2 years ago

Are you sure link generation can't be fixed on net7 ? So much energy is spent on minimal api and blarzors instead, not much on mvc I'm afraid :( I'v seen this movie on net5, then net6, now net7....

nfplee commented 2 years ago

@valeriob I echo your thoughts about MVC. So much wasted energy is being spent on improvements to minimal API just to mimic what you can already do in MVC. As for Blazor, how about showing some love for people that use alternatives such as htmx and/or petite-vue/alpine.js which compliment MVC and razor pages.

The link generation improvements would benefit everyone. The specific issue I'm concerned with is https://github.com/dotnet/aspnetcore/issues/16960 which was a regression introduced with endpoint routing and has still not been addressed.