<legend id='idjNU'><style id='idjNU'><dir id='idjNU'><q id='idjNU'></q></dir></style></legend>

    • <bdo id='idjNU'></bdo><ul id='idjNU'></ul>

      <small id='idjNU'></small><noframes id='idjNU'>

        <i id='idjNU'><tr id='idjNU'><dt id='idjNU'><q id='idjNU'><span id='idjNU'><b id='idjNU'><form id='idjNU'><ins id='idjNU'></ins><ul id='idjNU'></ul><sub id='idjNU'></sub></form><legend id='idjNU'></legend><bdo id='idjNU'><pre id='idjNU'><center id='idjNU'></center></pre></bdo></b><th id='idjNU'></th></span></q></dt></tr></i><div id='idjNU'><tfoot id='idjNU'></tfoot><dl id='idjNU'><fieldset id='idjNU'></fieldset></dl></div>
        <tfoot id='idjNU'></tfoot>

        ASP.NET Core Razor 视图中的递归

        时间:2023-07-10
        <tfoot id='y2bKI'></tfoot>
          <bdo id='y2bKI'></bdo><ul id='y2bKI'></ul>

            <small id='y2bKI'></small><noframes id='y2bKI'>

          • <i id='y2bKI'><tr id='y2bKI'><dt id='y2bKI'><q id='y2bKI'><span id='y2bKI'><b id='y2bKI'><form id='y2bKI'><ins id='y2bKI'></ins><ul id='y2bKI'></ul><sub id='y2bKI'></sub></form><legend id='y2bKI'></legend><bdo id='y2bKI'><pre id='y2bKI'><center id='y2bKI'></center></pre></bdo></b><th id='y2bKI'></th></span></q></dt></tr></i><div id='y2bKI'><tfoot id='y2bKI'></tfoot><dl id='y2bKI'><fieldset id='y2bKI'></fieldset></dl></div>

                  <tbody id='y2bKI'></tbody>
                1. <legend id='y2bKI'><style id='y2bKI'><dir id='y2bKI'><q id='y2bKI'></q></dir></style></legend>
                  本文介绍了ASP.NET Core Razor 视图中的递归的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我现在有以下代码来编写带有指向控制器操作的链接的平面项目列表:

                  I have the following code right now to write a flat list of items with a link to a controller action:

                  <ul>
                      @foreach (var item in items)
                      {
                          <li>
                              <a asp-controller="Home" asp-action="Demo" asp-route-itemName="@item.Name">
                                  @item.Name
                              </a>
                          </li>
                      }
                  </ul>
                  

                  现在这必须变成递归的.项目还可以包含子项目.对于递归,我需要某种功能.我知道我可以使用 @functions 并在 .cshtml 文件中定义函数.不确定这种带有标签助手的漂亮的内联 HTML 代码是否仍然允许在那里,似乎不是这样.另一种选择是 .cs 文件中的 HTML 帮助程序,这里肯定没有内联 HTML.@helper 似乎不再可用.

                  Now this must become recursive. Items can also contain subitems. For recursion I need some sort of function. I know I could use @functions and define the function in the .cshtml file. Not sure whether such nice inline HTML code with tag helpers would still be allowed there, it didn't seem so. Another option is HTML helpers in a .cs file, no inline HTML here for sure. @helper doesn't seem to be available anymore.

                  还有哪些其他选项可以定义函数并保留 Razor 提供的内联 HTML 语法?

                  What other options do I have to define a function and keep the inline HTML syntax that Razor offers?

                  推荐答案

                  将渲染注释的代码放在局部视图中,并通过调用 @Html.Partial("comment", comment) 来渲染它.

                  Put the code for rendering a comment inside a partial view, and render it with a call to @Html.Partial("comment", comment).

                  然后在那个评论部分视图中你会有类似的东西

                  Then within that comment partial view you'd have something like

                  @model Comment
                  
                  Title: @Model.Title
                  Message: @Model.Message
                  
                  @if (Model.ChildComments.Any())
                  {
                      <ul>
                          @foreach (var childComment in Model.ChildComments)
                          {
                              <li>
                                  @Html.Partial("comment", childComment)
                              </li>
                          }
                      </ul>
                  }
                  

                  这将递归地呈现每条评论及其所有子项(如果有).

                  This will render each comment, plus all its children (if any), recursively.

                  这篇关于ASP.NET Core Razor 视图中的递归的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:MVC6 中的 ASP 标识 - 登录路径属性不起作用 下一篇:如何注销 ASP.NET Core cookie 身份验证中的所有用户?

                  相关文章

                    1. <i id='gJcIY'><tr id='gJcIY'><dt id='gJcIY'><q id='gJcIY'><span id='gJcIY'><b id='gJcIY'><form id='gJcIY'><ins id='gJcIY'></ins><ul id='gJcIY'></ul><sub id='gJcIY'></sub></form><legend id='gJcIY'></legend><bdo id='gJcIY'><pre id='gJcIY'><center id='gJcIY'></center></pre></bdo></b><th id='gJcIY'></th></span></q></dt></tr></i><div id='gJcIY'><tfoot id='gJcIY'></tfoot><dl id='gJcIY'><fieldset id='gJcIY'></fieldset></dl></div>
                      <tfoot id='gJcIY'></tfoot>

                    2. <small id='gJcIY'></small><noframes id='gJcIY'>

                      <legend id='gJcIY'><style id='gJcIY'><dir id='gJcIY'><q id='gJcIY'></q></dir></style></legend>
                        <bdo id='gJcIY'></bdo><ul id='gJcIY'></ul>