gpt4 book ai didi

c# - 扩展 ASP.net HelpPage 主页

转载 作者:太空宇宙 更新时间:2023-11-03 13:05:27 24 4
gpt4 key购买 nike

我一直在使用 ASP.net HelpPages 为我的 ApiControllers 生成文档。现在帮助页面的索引显示 Controller 的名称/路径和 Controller 的描述。

CONTROLLER NAME
------------------------------------------------------------
Api Description
------------------------------------------------------------
GET api/Admin/Users Some vague description here.
POST api/Admin/Users Another vague description here.

我想在索引屏幕上显示有关 Controller 的更多信息。

CONTROLLER NAME
--------------------------------------------------------------------
Api Description Permissions Field2
---------------------------------------------------------------------
GET api/Admin/Users Description here. Admin 48
POST api/Admin/Users Description here. Regular 92

简而言之,我想将 View 从第一个 View (只是 api/描述)扩展到第二个 View (扩展)。

编辑:我在 ApiGroup.cshtml 和 HelpPageConfigurationExtensions 中放置了断点。cs 并且索引页面的呈现似乎在将属性添加到 HelpPageApiModel 之前运行。

最佳答案

我无法使用我用于将信息添加到 Controller 的各个页面的相同方法,因为在 HelpPageConfigurationExtensions.cs 中生成 ApiModel 之前呈现索引页面。可能是因为他们不想等待几千年来加载索引页面。

为了解决这个问题,我将逻辑直接添加到 ApiGroup.cshtml 文件中。我想包含在索引页面上的其他参数是从可以通过 ApiDescription 对象访问的属性派生的。

这看起来像:

(ApiGroup.cshtml)

@foreach (var api in Model)
{
<tr>
<td class="api-name"><a href="@Url.Action("Api", "Help", new {apiId = api.GetFriendlyId()})">@api.HttpMethod.Method @api.RelativePath</a></td>
<td class="api-documentation">
@if (api.Documentation != null)
{
<p>@api.Documentation</p>
}
else
{
<p>No documentation available.</p>
}
</td>
<td class="api-Type1">
@DisplayType1Information(api)
</td>
<td class="api-Type2">
@DisplayType2Information(api)
</td>
</tr>
}

这是我的一个助手的示例,它保存 displayType1 信息的逻辑:

@helper DisplayType1Information(ApiDescription api)
{
string typeOfType1 = "None";
Type1 attribute =
api.ActionDescriptor.GetCustomAttributes<Type1Attribute>().FirstOrDefault();
if (attribute != null)
{
enum enumType = attribute.enumOfType1;
typeOfType1 = enumType.ToString();
}
<p>@typeOfType1</p>
}

我想在 .cshtml 文件中添加太多逻辑是一种不好的做法,因为它可能会减慢页面加载速度,但这似乎对页面没有任何影响。

关于c# - 扩展 ASP.net HelpPage 主页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30920261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com