dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.42k stars 25.34k forks source link

Razor 代码块,使用标记将本地函数声明为用作模板化方法 #32582

Closed 1940169701 closed 1 month ago

1940169701 commented 1 month ago

Description

原文

在代码块中,使用标记将本地函数声明为用作模板化方法:

@{
    void RenderName(string name)
    {
        <p>Name: <strong>@name</strong></p>
    }

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

该代码呈现以下 HTML:

<p>Name: <strong>Mahatma Gandhi</strong></p>
<p>Name: <strong>Martin Luther King, Jr.</strong></p>

代码效果

image

Page URL

https://learn.microsoft.com/zh-cn/aspnet/core/mvc/views/razor?view=aspnetcore-8.0

Content source URL

https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/mvc/views/razor.md

Document ID

a0b3b70a-3b39-1b5f-a4ce-c41bd2d6b044

Article author

@Rick-Anderson

1940169701 commented 1 month ago

好吧,这是asp.net core的文章...

Rick-Anderson commented 1 month ago

Hello! Thanks for contacting us. This sounds like a general question about using ASP.NET Core. While we try to look at and respond to all issues, for questions like this we recommend posting to a community support group like Stack Overflow with the asp.net-core tag.

Potential bugs in the ASP.NET Core framework and product feedback can be reported at dotnet/aspnetcore issues (include full repro steps and cross-link to a repro project in GH when appropriate). For Visual Studio, use the Report a Problem gesture or Suggest a Feature gesture within VS, which open internal issues for the VS team. For Visual Studio Code, you can open an issue at microsoft/vscode issues.