Thursday, 11 March 2021

MVC - WebApiConfing - Fix Error - The requested resource does not support http method 'GET'

 Watch this example on YouTube


 to fix it add to the controller


        [System.Web.Http.AcceptVerbs("GET", "POST")]
        [System.Web.Http.HttpGet]


so it looks like

using System.Web.Mvc;

namespace WebApplication11.Controllers
{
    [RoutePrefix("api/Device")]
    public class TestController : System.Web.Http.ApiController
    {
        [System.Web.Http.AcceptVerbs("GET", "POST")]
        [System.Web.Http.HttpGet]

        public string f1()
        {
            return "hello world";
        }
        public string f1(int a)
        {
            return (a + 1).ToString();
        }
    }
}

No comments:

Post a Comment