DNN SPA模块中的路由未按预期工作

时间:2018-08-17 13:19:20

标签: dotnetnuke dotnetnuke-9

我似乎无法弄清楚如何访问我的一个控制器上的方法,“设置”控制器可以正常工作...

ServiceRouteMapper:

public void RegisterRoutes(IMapRoute mapRouteManager)
{
       mapRouteManager.MapHttpRoute(
           moduleFolderName: "ImportantDatesModule",
           routeName: "default",
           url: "{controller}/{action}/{id}",
           defaults: new { id = RouteParameter.Optional },
           namespaces: new[] { "company.ImportantDatesModule.Services" });
}

控制器:

[SupportedModules("ImportantDatesModule")]
[DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)]
public class ItemController : DnnApiController
...

[HttpGet]
[ActionName("getItems")]
public HttpResponseMessage GetItems() 
{
    return Request.CreateResponse(HttpStatusCode.OK, "success");
}

正在执行呼叫的JS文件:

dnnspamodule.itemsViewModel = function (moduleId, resx) {
var service = {
    path: "ImportantDatesModule",
    framework: $.ServicesFramework(moduleId),
    controller: "Item"
}
service.baseUrl = service.framework.getServiceRoot(service.path);
...

var getItems = function () {
    var restUrl = service.baseUrl + service.controller + "/getItems";
    console.log(restUrl);

    isLoading(true);
    var jqXHR = $.ajax({
        url: restUrl,
        beforeSend: service.framework.setModuleHeaders,
        dataType: "json"
    }).done(function (data) {
        if (data) {
            load(data);
            isLoading(false);
        }
        else {
            // No data to load 
            itemList.removeAll();
        }
    }).always(function (data) {

    });
};

1 个答案:

答案 0 :(得分:2)

我不知道您的“设置”控制器的外观如何,但也许尝试将您的路线分为动作样式({controller} / {action})和休息风格的路线({controller} / {id} +中的派生动词方法名称)。在您的服务路线映射器中尝试以下操作:

mapRouteManager.MapHttpRoute(
    moduleFolderName: "ImportantDatesModule",
    routeName: "default", 
    url: "{controller}/{action}",
    namespaces: new[] {"company.ImportantDatesModule.Services"});

mapRouteManager.MapHttpRoute(
    moduleFolderName: "ImportantDatesModule",
    routeName: "rest",
    url: "{controller}/{id}",
    defaults: new { id = RouteParameter.Optional },
    namespaces: new[] { "company.ImportantDatesModule.Services" });