4

Reading the latest documentation for ASP.Net Core 3.1, it is now recommended to use Razor Components over View Components. From 1,000 feet, this looks like a great idea as there is a single-file now instead of a "controller" and a default "view". More precise, compact, and I am assuming more efficient.

One big of information that took me by surprise, was the fact that tag helpers aren't supported in Razor Components (reference):

Tag Helpers aren't supported in Razor components (.razor files). To provide Tag Helper-like functionality in Blazor, create a component with the same functionality as the Tag Helper and use the component instead.

Am I the only one in all of the .NET world that thinks this is absolutely not acceptable? In view components, tag helpers are supported and are the single-most useful bits of .NET MVC. A simple example is the anchor tag helper. That is the most useful helper in my opinion as it accepts area, controller, action, and a dynamic parameter list that generates an anchor tag without you having to worry about figuring out the routing.

Enough griping, to turn this into a question, how would one do this now in a Razor Component? The example on Microsoft's documentation for the tag helper is the ability to create a navigational menu using the tag helpers in a view component. Now, on the view component page, it is recommended to use Razor Components over View Components (reference):

When considering if view components meet an app's specifications, consider using Razor Components instead. Razor Components also combine markup with C# code to produce reusable UI units. Razor Components are designed for developer productivity when providing client-side UI logic and composition.

So, if one were to create a navigational menu in ASP.NET Core 3.1 (MVC) using Razor Components, what would be the easiest way to accomplish this without having to document every single route in Startup?

clockwiseq
  • 4,189
  • 9
  • 38
  • 61
  • Razor Components is for blazor project, do you mean you want to add blazor support to your mvc project? – Ryan Feb 03 '20 at 02:24
  • Well, maybe I misunderstood the Microsoft documentation because the page was for ASP.NET Core 3.1 and on the View Component page. It says they recommend you use Razor Components instead. Am I missing something? – clockwiseq Feb 03 '20 at 04:37
  • Maybe you could refer to [this link](https://stackoverflow.com/questions/59328798/razor-components-vs-view-components).Razor component is more powerful but you need to add [blazor support](https://learn.microsoft.com/en-us/aspnet/core/blazor/components?view=aspnetcore-3.1#integrate-components-into-razor-pages-and-mvc-apps) in order to use it. – Ryan Feb 03 '20 at 05:01

0 Answers0