Umbraco AJAX call not working

萝らか妹 提交于 2020-01-04 09:08:08

问题


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:

  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");


来源:https://stackoverflow.com/questions/24508306/umbraco-ajax-call-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!