config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data")))
//private XPathNavigator _documentNavigator; private List<XPathNavigator> _documentNavigators = new List<XPathNavigator>();
1.2.二、找到類的方法 XmlDocumentationProvider ,修改以下:css
public XmlDocumentationProvider(string documentPath) { if (documentPath == null) { throw new ArgumentNullException("documentPath"); } //註釋這兩行 //XPathDocument xpath = new XPathDocument(documentPath); //_documentNavigator = xpath.CreateNavigator(); //新增以下 DirectoryInfo theFolder = new DirectoryInfo(documentPath); foreach (var item in theFolder.GetFiles("*.xml")) { XPathDocument xpath = new XPathDocument(Path.Combine(documentPath, item.Name)); _documentNavigators.Add(xpath.CreateNavigator()); } }
private XPathNavigator SelectSingleNode(string selectExpression) { foreach (var navigator in _documentNavigators) { var propertyNode = navigator.SelectSingleNode(selectExpression); if (propertyNode != null) return propertyNode; } return null; }
注意:新建的控制器必須繼承 ApiController 不然界面不會展現控制器接口!html
2.一、經過Nuget包管理添加 webapitestclient ,添加完成後找到這個 Areas->HelpPage->Views->Help 路徑下的 Api.cshtml 文件,修改以下web
@using System.Web.Http @using API.Areas.HelpPage.Models @model HelpPageApiModel @*解析html*@ @section Scripts { @Html.DisplayForModel("TestClientDialogs") @Html.DisplayForModel("TestClientReferences") } @{ var description = Model.ApiDescription; ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath; } <link type="text/css" href="~/Areas/HelpPage/HelpPage.css" rel="stylesheet" /> <div id="body" class="help-page"> <section class="featured"> <div class="content-wrapper"> <p> @Html.ActionLink("Help Page Home", "Index") </p> </div> </section> <section class="content-wrapper main-content clear-fix"> @Html.DisplayForModel() </section> </div>