2014-03-12 122 views
13

我正在使用XML文檔爲我的ASP.NET Web API幫助頁面as shown here。 我想知道是否有一種方法可以在評論中包含html,這樣它就會呈現在網頁上,而不是被刪除/忽略/轉義。
具體來說,我正在尋找一種方法來創建一個換行符,但是能夠創建項目符號列表等等會很棒!Web Api幫助頁面 - 在xml文檔中不轉義html

防爆/我希望能夠做這樣的事情:

/// <summary> 
/// CRUD operations for SalesDocument<br/> 
/// This is a new line 
/// </summary> 
[RoutePrefix("api/SalesDocument")] 
public partial class SalesDocumentController : ApiController 

而且有它顯示幫助頁面這樣的:

CRUD operations for SalesDocument 
This is a new line. 

取而代之的是:(本情況下,<br/>被莫名其妙地刪除 - 如果我嘗試使用<p>標籤,他們剛剛逃脫)

CRUD operations for SalesDocument This is a new line. 

*我已經嘗試了多個帖子提示的<para>標籤,但這不適用於我的幫助頁面。

任何建議,非常感謝!

回答

28

在安裝XmlDocumentationProvider.cs文件在Areas\HelpPage,你可以找一個名爲「GetTagValue」的方法......這裏從「node.Value.Trim()」到「node.InnerXml」修改返回值。

private static string GetTagValue(XPathNavigator parentNode, string tagName) 
{ 
    if (parentNode != null) 
    { 
     XPathNavigator node = parentNode.SelectSingleNode(tagName); 
     if (node != null) 
     { 
      return node.InnerXml; 
     } 
    } 

    return null; 
} 

現在打開安裝文件Areas\HelpPage\Views\Help\DisplayTemplates\ApiGroup.cshtml和修改下面一行:

<p>@controllerDocumentation</p> 

<p>@Html.Raw(controllerDocumentation)</p> 
+0

太棒了! 「@ Html.Raw」是我失蹤的關鍵......感謝你的好先生,你剛剛度過了我的一天! =) –

+13

我想知道爲什麼它不適合我,然後我意識到它需要在多個地方完成(取決於你想要標籤工作的地方)。我做的是ApiGroup.cshtml,HelpPageApiModel.cshtml和ResourceModel.cshtml(在每個文件中查找.Documentation和.RequestDocumentation)。認爲它可能會幫助下一個發現這個:) :) – zeroid

+3

我不得不改變'GetDocumentation'中的'return parameterNode.InnerXml;'以使用參數部分 –

-1

@controllerDocumentation對我不起作用,但改變行@api.Documentation作品。即@html.raw(api.Documentation)