Last post Mar 13, 2020 10:15 AM by Sherry Chen
Mar 10, 2020 11:05 PM|zxcvbdnm|LINK
Is it possible to use the <a> tag helper to generate a hyperlink to a Razor Component which has a @page directive?
This is in a mostly Razor-Pages project which uses Server-Side Blazor and has routing for both Razor pages and Razor 'Component-Pages'.
The /pages folder has a mix of `.cshtml` files and `.razor` files.
Routing is currently working properly for both Razor Pages and Razor Components with @page directives.
Mar 11, 2020 02:23 AM|DA924|LINK
Why do you need an <a> tag helper? You can't make an <a> using href,?
the path is.
Pages/Author Pages/Payroll Pages/Article, etc., etc.
ViewData["Title"] = "Author Page";
<meta name="viewport" content="width=device-width" />
<br /><br />
<table border="1" cellpadding="10">
@foreach (var item in Model.AuthorVM.Authors)
onclick="return confirm('Are you sure, you want to delete this author?')">Delete</a>
Mar 11, 2020 07:11 AM|Sherry Chen|LINK
Hi zxcvbdnm ,
Not clear about what you want. Did you want to click the <a> tag helper in
Razor Component and then call the handler of the razor page ?
What's the code you have tried ? And what's the actual result and the expected result ?
Could you share the relevant code so that we can help you better ?
Mar 11, 2020 03:33 PM|zxcvbdnm|LINK
expected to produce
I'm now realizing being able to do this isn't as important as I thought it might be (kinda)...
What I really want is a better way to link between Razor Pages / Razor Components (w/@page directive).
Ultimately, what I'm looking for is a way to refactor the names of pages (and maybe even query params) without needing to manually change every `href` smattered around my application.
What is the best solution here?
Even ignoring Razor Components and just using Razor Pages I can't see one. When I used MVC I could link to the nameof() the action and that was a bit better I think, but not a complete solution still.
I suppose my original question might have been a bit off.
Thanks for the help!
Mar 11, 2020 06:17 PM|DA924|LINK
If you expected the above, then why don't you just use it? I found out that the <a> helper tag doesn't always create the needed HTML pathing. So I just didn't use the helper tag, and created what I needed.
Mar 13, 2020 10:15 AM|Sherry Chen|LINK
Hi zxcvbdnm ,
As bruce suggested , using directly "href" would be a better choice.
asp-page represnts the razor page to link to and it can not be used for raozr component . Refer to the below: