how to bind to taghelper property in razor pages?

mc 6,396 Reputation points
2023-01-30T05:36:04.64+00:00

[HtmlTargetElement("pagination")]

public class PaginationTagHelper : TagHelper

{

[HtmlAttributeName("page-index")]

public int PageIndex{get;set;}

}

and in Index.cshtml

<pagination page-index="PageIndex" />

I can not bind to PageIndex property in Index.cshtml.cs

public int PageIndex{get;set;}

how to bind PageIndex to TagHelper property?

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | ASP.NET | Other
{count} votes

Answer accepted by question author
  1. Xinran Shen - MSFT 2,091 Reputation points
    2023-01-31T08:38:29.36+00:00

    Hi 打玻璃, Combining with the previous question I answered, you want to bind and render the value of PageIndex into <div>xxx</div> right? Because <div></div> is not a self-closing tag, So you need to use:

    <pagination page-index="Name" ></pagination>

    instead of

    <pagination page-index="Name" />

    to render it. Please refer:

    User's image

    Then the Name can be bind and render successfully:

    User's image


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    Best regards,

    Xinran Shen


0 additional answers

Sort by: Most helpful

Your answer

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