[英]ASP.NET web.api Help Page does not show any description
當我運行我的程序時,它只顯示“在這里提供API的一般描述”。 但沒有內容顯示。 如下圖所示: http : //i.stack.imgur.com/unBmb.png
我的問題類似於這個ASP.NET Web Api幫助頁面沒有顯示任何提示,但它沒有提供任何解決方案。
我已經按照本教程http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages從“將幫助頁面添加到現有項目”除了“ValuesController”之外,所有內容都是從nuGet自動創建的。
我猜這就是問題所在。
我的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)
{
}
}
}
有沒有人有這方面的解決方案,或任何可能出錯的建議?
(我還制作了一個新的asp.net web api-project(從start開始包含valuescontroller),這個工作正常..)
我找到了解決方案!
第1步:我在Controller-folder中添加了一個valuesController,作為一個空的web api2 Controller。 然后粘貼教程中的代碼:
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";
}
}
}
第2步:將此代碼添加到route.config(如果您從頭開始創建api項目,則會自動創建),因此在本教程中未提及。
routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
當我運行該程序時,它工作。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.