问题
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:
Check different things:
- reboot the site (touch the web.config)
- 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.
- what do the log files in /App_Data/Logs tell you?
You can insert your own logs by invokingLogHelper.Info<myclass>("some message")
- 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?
- are you sure your controller inherits from
- 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");
来源:https://stackoverflow.com/questions/24508306/umbraco-ajax-call-not-working