How do I define a method in Razor?

后端 未结 8 672
余生分开走
余生分开走 2020-11-28 05:57

How do I define a method in Razor?

相关标签:
8条回答
  • 2020-11-28 06:19

    Razor is just a templating engine.

    You should create a regular class.

    If you want to make a method inside of a Razor page, put them in an @functions block.

    0 讨论(0)
  • 2020-11-28 06:24

    You could also do it with a Func like this

    @{
        var getStyle = new Func<int, int, string>((width, margin) => string.Format("width: {0}px; margin: {1}px;", width, margin));
    }
    
    <div style="@getStyle(50, 2)"></div>
    
    0 讨论(0)
提交回复
热议问题