【问题标题】:ASP.NET web.api Help Page does not show any descriptionASP.NET web.api 帮助页面不显示任何描述
【发布时间】:2015-09-24 15:45:10
【问题描述】:

当我运行我的程序时,它只显示“在此处提供您的 API 的一般描述”。但没有显示内容。就像这张图:http://i.stack.imgur.com/unBmb.png

我的问题与ASP.NET Web Api Help Page doesn't show any tips 类似,但没有提供任何解决方案。

我已按照“将帮助页面添加到现有项目”中的本教程http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages 进行操作,并且所有内容都是从 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(其中包含从一开始的 valuescontroller),这工作正常..)

【问题讨论】:

    标签: c# asp.net asp.net-mvc asp.net-web-api-helppages


    【解决方案1】:

    我找到了解决办法!

    第 1 步:我在 Controller 文件夹中添加了一个 valuesController,作为一个空的 web api2 控制器。然后粘贴教程中的代码:

    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 }
            );
    

    当我运行程序时,它起作用了。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      相关资源
      最近更新 更多