Shared MVC Razor functions in several views

后端 未结 3 1585
眼角桃花
眼角桃花 2021-02-02 07:23

I have functions in my view that is shared by several pages:

@functions 
{
    public HtmlString ModeImage(ModeEnum mode) 
    {
        switch(mode)
        {
          


        
3条回答
  •  滥情空心
    2021-02-02 07:53

    You could make a static helper page and put a normal static method in the page.
    You could then call it by writing PageName.MyMethod() anywhere, and I believe that you won't need to recompile the project.

提交回复
热议问题