2
votes

I have a MVC application where I have installed umbraco 6.1.6 nuget package.Now I am trying to call a controller from a view using Jquery AJAX function. The controller is placed in MVC controller folder and it is inherited with UmbracoApiController. I have tried to follow the Umbraco API document ,But everytime my request is send it redirects to 404 page. I have tried the same using umbraco 7.1.4 downloaded from here and it works fine for me. Can anyone suggest a solution for this.

The request url I have used is as follows :- /Umbraco/Api/[ControllerName]/[ActionName], I have also tried /Umbraco/[YourAreaName]/[YourControllerName] , but that too doesn't work for me.

1
Can you post the code of your controller so we can see whether it has correct attributes for HTTP verbs specified? Also, routes are case-sensitive, so you need to try /umbraco/api/ControllerName/MethodName (note lowercase in first two paths).Jamie Howarth

1 Answers

2
votes

Check different things:

  1. reboot the site (touch the web.config)
  2. did you BUILD the code? If you put it in app_code is it picked up automatically, otherwise you need the DLL to be in your bin directory.
  3. what do the log files in /App_Data/Logs tell you?
    You can insert your own logs by invoking LogHelper.Info<myclass>("some message")
  4. are you really really really sure you have not overlooked something from the documentation?
    • are you sure your controller inherits from UmbracoApiController
    • have you tried adding [MemberAuthorize(AllowAll = true)] to the api controller or the method?
  5. double check the URL. you probably mistyped the name. The controller is the complete name without "controller". Try the code below to find back the exact url.

The code below came from a usercontrol which i used in a dashboard for the end user. I guess it's pretty easy to convert it into a Razor macro. If this is not returning a thing, you did something wrong from the list above.

var requestHandler = HttpContext.Current.Request.RequestContext;
var urlHelper = new UrlHelper(requestHandler);
var actionlink = Umbraco.Web.UrlHelperExtensions.GetUmbracoApiService<MyApiController>(urlHelper, "MyMethodName");