How to create a function in a cshtml template?

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

    If you want to access your page's global variables, you can do so:

    @{
        ViewData["Title"] = "Home Page";
    
        var LoadingButtons = Model.ToDictionary(person => person, person => false);
    
        string GetLoadingState (string person) => LoadingButtons[person] ? "is-loading" : string.Empty;
    }
    

提交回复
热议问题