0

I want to create help pages for ASP.NET Web API.

I created a new ASP.NET Web application project and select the Web API project template. It added Areas/HelpPage.

When I run the application, the home page contains a link to the API help page. From the home page, the relative path is /Help. It shows ValuesController action, but when I add another controller, the help page doesn't show that controller and any of its actions.

public class CalendarController : ApiController
{
    private readonly string siteUrl = ConfigurationManager.AppSettings["SiteUrl"];
    private readonly CalendarService calendarService;

    public CalendarController()
    {
        calendarService = new CalendarService();
    }

    [HttpPost]
    public async Task<ResponseModel<List<ApiCalendarViewModel>>> Paging(JObject param)
    {
        try
        {
            var startIndex = Convert.ToInt32(param["StartIndex"]);
            var pageSize = Convert.ToInt32(param["PageSize"]);
            var CalendarList = await calendarService.SelectAllAsync(startIndex, pageSize);

            var list = CalendarList.Select(m => new ApiCalendarViewModel()
            {
                Author = m.Author,
                Date = PersianDateTime.ToLongDateWithDayString(m.CreatedDate),
                Excerpt = m.Excerpt,
                Id = m.Id,
                MainImage = siteUrl + m.Image,
                Title = m.Title,
                StartYear = m.StartYear,
                EndYear = m.EndYear,
                Semester = m.Semester.GetDisplayName()
            }).ToList();

            return new ResponseModel<List<ApiCalendarViewModel>>()
            {
                IsSuccess = true,
                Data = list
            };
        }
        catch (Exception e)
        {
            return new ResponseModel<List<ApiCalendarViewModel>>()
            {
                IsSuccess = false,
                Message = e.Message
            };
        }
    }

    [HttpGet]
    public async Task<ResponseModel<List<ApiCalendarViewModel>>> GetAll()
    {
        try
        {
            var CalendarList = await calendarService.SelectAllAsync();
            var list = CalendarList.Select(m => new ApiCalendarViewModel()
            {
                Author = m.Author,
                Date = PersianDateTime.ToLongDateWithDayString(m.CreatedDate),
                Excerpt = m.Excerpt,
                Id = m.Id,
                MainImage = siteUrl + m.Image,
                Title = m.Title,
                StartYear = m.StartYear,
                EndYear = m.EndYear,
                Semester = m.Semester.GetDisplayName()
            }).ToList();

            return new ResponseModel<List<ApiCalendarViewModel>>()
            {
                IsSuccess = true,
                Data = list
            };
        }
        catch (Exception e)
        {
            return new ResponseModel<List<ApiCalendarViewModel>>()
            {
                IsSuccess = false,
                Message = e.Message
            };
        }
    }
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ar.gorgin
  • 4,765
  • 12
  • 61
  • 100
  • There are similar question in this site which may help you : 1: https://stackoverflow.com/questions/37547007/asp-net-helppages-not-showing-my-controllers 2: https://stackoverflow.com/questions/27154090/web-api-help-page-show-only-some-controllers-but-no-others . Remember that common questions had been already answered before. Even having a look at right side of this web page, shows more related questions. – morteza Nov 06 '22 at 16:31

0 Answers0