1.新建一个WebApi项目
2.用Nuget添加Microsoft ASP.NET Web API Help Page包
3.修改HelpPageConfig文件
public static void Register(HttpConfiguration config){// Uncomment the following to use the documentation from XML documentation file.config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/PatientView.Service.WebAPI.xml")));...}
4.API方法上写三斜杠的注释
/// <summary>/// 病区列表/// </summary>/// <returns></returns>[Route("GetLocationUnits")]public Response<List<LocationUnitModel>> GetLocationUnits(){return TryResponse(() => _operatorBll.GetLocationUnits(),method: "GetLocationUnits");}
5.打开项目属性,在Build页面里,勾选XML documentation file
App_Data\PatientView.Service.WebAPI.xml
6.用Nuget添加Install
the WebApiTestClient package (可以搜索yaohuang)
7.修改文件under
Areas\HelpPage\Views\Help 下的Api.cshtml
添加
- @Html.DisplayForModel("TestClientDialogs")
- @Html.DisplayForModel("TestClientReferences") 如下
@using System.Web.Http@using MyApi.Areas.HelpPage.Models@model HelpPageApiModel@{var description = Model.ApiDescription;ViewBag.Title = description.HttpMethod.Method + " " + description.RelativePath;}<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>@Html.DisplayForModel("TestClientDialogs")@section Scripts{@Html.DisplayForModel("TestClientReferences")<link type="text/css" href="~/Areas/HelpPage/HelpPage.css" rel="stylesheet" />}
8.添加以下文件修改样式
- jQuery 1.7.1
- jQuery.UI.Combined 1.8.20
- knockoutjs 2.1.0
效果: