Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
402 views
in Technique[技术] by (71.8m points)

asp.net web api - WebApi Help Page: don't escape HTML in XML documentation

I am using XML Documentation for my ASP.NET Web API Help Page as shown here. I would like to know if there is a way to include html in the comments such that it will be rendered on the web page, instead of it being removed/ignored/escaped.
Specifically, I am looking for a way to create a newline, but being able to create bulleted lists, etc. would be great!

Ex/ I would like to be able to do something like this:

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

And have it show on the help page like this:

CRUD operations for SalesDocument 
This is a new line.

Instead of this: (in this case, <br/> gets removed somehow - if I try using <p> tags, they are just escaped)

CRUD operations for SalesDocument This is a new line.

*I have already tried the <para> tag as suggested by multiple posts for tooltips, but this does not work on my help page.

Any suggestions are greatly appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the installed XmlDocumentationProvider.cs file at AreasHelpPage, you can look for a method called GetTagValue. Here modify the return value from node.Value.Trim() to 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;
}

Now open the installed file AreasHelpPageViewsHelpDisplayTemplatesApiGroup.cshtml and modify the following line from:

<p>@controllerDocumentation</p>

to

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...