The asp-page or asp-route-id or asp-action not translated to html in razor pages?

mc 5,491 Reputation points
2021-05-18T06:41:51.867+00:00

I am using asp.net core web

In razor pages there is a asp-page but it is not translated to html.

<a asp-page="/Product/Add">Add</a>

the html is

<a href="" >Add</a>

why?

and also the asp-route-handler

<a asp-route-id="0" asp-route-handler="Delete">Delete</a>

is

<a href="">Delete</a>
Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Jerry Cai-MSFT 991 Reputation points
    2021-05-19T03:35:00.413+00:00

    Hi,65841535

    asp-handler can only assign page name:

    <a asp-page="/Product" >Product</a>  
    

    If you use this code, then html will generate:

    97673-image.png

    if you want to post to Add in Product, what is asp-route-handler? Is that your custom tag helper? Usually, you can use asp-page-handler like this:

    97648-image.png

    And OnPost should be added to action name, for pagehandler to find:

    public IActionResult OnPostAdd(int id)  
            {  
                //return RedirectToPage("/Privacy");  
            }  
    

    You can check more info about Razor Pages anchor tag helper in here:

    anchor-tag-helper


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.