[英]ASP.NET web.api Help Page does not show any description
When I run my program it only shows "Provide a general description of your APIs here." 当我运行我的程序时,它只显示“在这里提供API的一般描述”。 But no content is show.
但没有内容显示。 Like in this picture: http://i.stack.imgur.com/unBmb.png
如下图所示: http : //i.stack.imgur.com/unBmb.png
My problem is similar to this ASP.NET Web Api Help Page doesn't show any tips but it doesnt provide any solution. 我的问题类似于这个ASP.NET Web Api帮助页面没有显示任何提示,但它没有提供任何解决方案。
I have followed this tutorial http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages from "Adding Help Pages to an Existing Project" and everything is automatically created from the nuGet, except for the "ValuesController". 我已经按照本教程http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages从“将帮助页面添加到现有项目”除了“ValuesController”之外,所有内容都是从nuGet自动创建的。
I am guessing thats where the problem is. 我猜这就是问题所在。
My ValuesController: 我的ValuesController:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace WebApiHelperTest.Controllers
{
public class ValuesController : ApiController
{
/// <summary>
/// Gets some very important data from the server.
/// </summary>
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
/// <summary>
/// Looks up some data by ID.
/// </summary>
/// <param name="id">The ID of the data.</param>
public string Get(int id)
{
return "value";
}
// POST api/values
public void Post([FromBody]string value)
{
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
}
Does anyone have a solution for this, or any suggestions on where it might go wrong? 有没有人有这方面的解决方案,或任何可能出错的建议?
(I also made a new asp.net web api-project (which contains the valuescontroller from start) and this works fine..) (我还制作了一个新的asp.net web api-project(从start开始包含valuescontroller),这个工作正常..)
I found a solution! 我找到了解决方案!
Step 1: I added a valuesController in the Controller-folder, as an empty web api2 Controller. 第1步:我在Controller-folder中添加了一个valuesController,作为一个空的web api2 Controller。 Then pasted the code from the tutorial:
然后粘贴教程中的代码:
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace yournamespace.Controllers
{
public class ValuesController : ApiController
{
/// <summary>
/// Gets some very important data from the server.
/// </summary>
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
/// <summary>
/// Looks up some data by ID.
/// </summary>
/// <param name="id">The ID of the data.</param>
public string Get(int id)
{
return "value";
}
}
}
Step 2: Added the this code to the route.config (Which is automatically created if you make an api project from the beginning) thus, not mentioned in the tutorial. 第2步:将此代码添加到route.config(如果您从头开始创建api项目,则会自动创建),因此在本教程中未提及。
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
When I ran the program it worked. 当我运行该程序时,它工作。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.