如何使ASP.NET WEB API帮助页面的xml文档注释有新行 [英] How to make ASP.NET WEB API HELP PAGES Xml Documentation Comments to have new line
问题描述
我使用的ASP.NET Web API一个REST API开发的。我用帮助页面的NuGet包,以创建文档。我所遇到的一个问题是以下内容。对于我的模型对象,我有XML文档注释并成为他们的帮助页面为模型的每个成员描述。我想说明的某一部分是一个新行,但一切都在评论当属一个段落。我尝试添加< BR />
的意见,但没有帮助。有谁知道如何实现这一目标?
一个类似的问题已经在这里问:的Web API帮助页面 - 不要逃避在XML文档和接受的答案(通过的Kiran Challa - 中的ASP.NET Web API团队成员之一)描述了一个变通
我只是尝试它自己,它工作正常。
然而,而不是加入< BR /&GT
我的code的意见,从我改变了建议的解决方案
返回node.InnerXml;
到
返回node.InnerXml.Replace(\\ r \\ n,< BR />中)更换(\\ n,< BR />中)。
...并在评论中指出,有可能是你需要添加 @ Html.Raw()
,即<$ C $的几个地方C> ApiGroup.cshtml , HelpPageApiModel.cshtml
和 ResourceModel.cshtml
和一些部分意见为好。
要弄清楚哪些意见我已经改变,我基本上刚刚推出Chrome中的调试器来帮我检查HTML和查找文件的基础上,要进行更改。
I have a rest api developed using ASP.NET WEB API. I used help pages nuget package in order to create documentation. One problem I encountered is the following. For my model objects, I have xml documentation comments and they become descriptions on the help pages for each member of the model. I want certain part of the description to be on a new line, but everything in the comment comes as one paragraph. I tried to add <br/>
in the comments, but didn't help. Does anyone know how to achieve this?
A similar question has been asked here: Web Api Help Page- don't escape html in xml documentation and the accepted answer (which is given by Kiran Challa - one of the ASP.NET Web API team members) describes a work around.
I just tried it myself, and it works fine.
However, instead of adding <br/>
to my code comments, I changed the proposed solution from:
return node.InnerXml;
to:
return node.InnerXml.Replace("\r\n", "<br/>").Replace("\n", "<br/>");
... and as pointed out in the comments, there might be several places where you need to add @Html.Raw()
, i.e., ApiGroup.cshtml
, HelpPageApiModel.cshtml
, and ResourceModel.cshtml
and some of the partial views as well.
To figure out which views I had to change, I basically just launched the debugger in Chrome to help me inspect the html and locate the files to be changed based on that.
这篇关于如何使ASP.NET WEB API帮助页面的xml文档注释有新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!