How to create a function in a cshtml template?

后端 未结 6 859
醉话见心
醉话见心 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:53

    You can use the @helper Razor directive:

    @helper WelcomeMessage(string username)
    {
        

    Welcome, @username.

    }

    Then you invoke it like this:

    @WelcomeMessage("John Smith")
    

提交回复
热议问题