Search code examples
c#asp.netasp.net-mvcasp.net-web-api-helppages

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." But no content is show. Like in this picture: https://i.sstatic.net/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.

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".

I am guessing thats where the problem is.

My 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..)


Solution

  • I found a solution!

    Step 1: I added a valuesController in the Controller-folder, as an empty 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.

    routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
            );
    

    When I ran the program it worked. :)