How to create a function in a cshtml template?

后端 未结 6 856
醉话见心
醉话见心 2020-12-02 04:06

I need to create a function that is only necessary inside one cshtml file. You can think of my situation as ASP.NET page methods, which are min web services implemented in a

6条回答
  •  清歌不尽
    2020-12-02 04:42

    In ASP.NET Core Razor Pages, you can combine C# and HTML in the function:

    @model PagerModel
    @{
    }
    
    @functions 
    {
        void PagerNumber(int pageNumber, int currentPage)
        {
            if (pageNumber == currentPage)
            {
                @pageNumber
            }
            else
            {
                @pageNumber
            }
        }
    }
    
    

    @PagerNumber(1,2) @PagerNumber(2,2) @PagerNumber(3,2)

提交回复
热议问题