Replacement for @helper in ASP.NET Core

后端 未结 8 1555
傲寒
傲寒 2020-11-30 06:35

So far, i don\'t think ViewComponent solves that neither does TagHelper. Is there any replacement to this? Something that takes parameters and retu

8条回答
  •  天命终不由人
    2020-11-30 06:59

    For .NET Core 3, you can use local functions:

    @{
        void RenderName(string name)
        {
            

    Name: @name

    } RenderName("Mahatma Gandhi"); RenderName("Martin Luther King, Jr."); }

    https://docs.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-3.1#razor-code-blocks

提交回复
热议问题