我想利用WebApi2的自动化文档功能以及IHttpActionResult.因此,我想更改以下代码:
/// <summary> /// Gets specified User /// </summary> /// <param name="id">User Id</param> /// <returns>The user</returns> public usermodel Get(int id) { usermodel result = new usermodel() { ErrorLevel = "Warning",ErrorMessage = "Not Implemented yet!" }; User u = new User() { Id = 1,ADUserName = "nfindlater",DefaultRoutingGroupId = 1 }; result.Data = u; var helper = new UrlHelper(Request); result.Url = helper.Link("User",new { userId = 1 }); return result; }
至
/// <summary> /// Gets specified User /// </summary> /// <param name="id">User Id</param> /// <returns>The user</returns> public IHttpActionResult Get(int id) { usermodel result = new usermodel() { ErrorLevel = "Warning",ErrorMessage = "Not Implemented yet!" }; User u = new User() { Id = 1,DefaultRoutingGroupId = 1 }; result.Data = u; var helper = new UrlHelper(Request); result.Url = helper.Link("User",new { userId = 1 }); return Ok<usermodel>(result); }
但是当我这样做时,我放松了/ Help / Api / GET-2013-12-05-user-id下自动生成的api文档的一部分.
以下是丢失的文档的一部分:
响应体格式
application / json,text / json
样品:
{
“url”:“sample string 1”,
“data”:{
“id”:1,
“adUserName”:“sample string 2”,
“name”:“sample string 3”,
“defaultRoutingGroupId”:4
},
“errorLevel”:“sample string 2”,
“errorMessage”:“sample string 3”
}
解决方法
原文地址:https://www.jb51.cc/aspnet/250945.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。