0

I am creating a controller and inheriting GlassController, I am trying to call controller action method using ajax and the URL requested is '/api/sitecore/TestForms/TestFormsAPI' and it throws an exception saying "The controller for path '/api/sitecore/TestForms/TestFormsAPI' was not found or does not implement IController."

Attached are the screen shot of my code and exception: enter image description here enter image description here

Can anyone suggest what could be the issue?

Akhil
  • 165
  • 1
  • 13

2 Answers2

1

Sitecore has a different way of routing. This may be conflicting with the default Sitecore Client route. Implement this using custom route. Follow this link - https://kb.sitecore.net/articles/700677

I shall also suggest to use Route attribute instead and this is how it can be done. (I havent tested following code)

 [RoutePrefix("api/Custom")]
public class MyCustomController : ApiController
{
    ICustomRepository _customRepository;
    public MyCustomController(ICustomRepository  _customRepository
    {
        _customRepository= customRepository
    }

    [Route("GetCustomMethod")]
    [HttpPost]
    public IHttpActionResult GetCustomMethod()
    {           
    ......
    ......            
        return Ok(results);
    }
}
Sandeep Pote
  • 161
  • 8
0

Had the custom route registered as in the article in sandy's answer (https://kb.sitecore.net/articles/700677), however it kept crashing with the same error because I included "Controller" when specifying the controller name, removing it fixed the issue (see https://stackoverflow.com/a/41901846/712700).

goamn
  • 1,939
  • 2
  • 23
  • 39