Umbraco 在后台找不到路线 [英] Umbraco cannot find the route in backoffice

查看:31
本文介绍了Umbraco 在后台找不到路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了 Umbraco 7.3.我创建了一个自定义数据类型,但是当我想在这里调用 SurfaceControllerHelloSurfaceControllerHello2SurfaceController 时,我在 umbraco 后台出现错误说请求错误:URL返回404(未找到):

我研究了一些关于路由的文章,但我无法解决我的问题.我不知道我哪里做错了.

我该如何解决这个问题?

<块引用>

回复.controller.js:

angular.module("umbraco").controller("Reply.controller", function ($scope, $http) {$scope.SendReply = 函数 () {var sendTo = $("#Email").val();var textMessage = $("#TextMessage").val();$scope.xxx = "我来了!";var data = { SendTo: sendTo, TextMessage: textMessage };//~/Hello2Surface/ReplyMessage --->找不到这个网址$http.post("~/App_Plugins/Reply/HelloSurface/ReplyMessage")//找不到这个网址.then(功能(响应){警报(是!");//去做:});}});

<块引用>

表面控制器

 命名空间 Jahan.Nuts.Web.Mvc.UmbracoCms.App.App_Plugins.Reply{公共类 HelloSurfaceController : SurfaceController{[HttpPost][ChildActionOnly]公共 ActionResult ReplyMessage(){//TODO:应该如何编写适合从angularjs获取数据的方法?返回空;}}}

<块引用>

package.manifest

<代码>{属性编辑器:[{别名: "Send.Reply",name: "发送回复",{视图:~/App_Plugins/Reply/Reply.html"},}],javascript:['~/App_Plugins/Reply/Reply.controller.js']}

<块引用>

回复.html

<div style="width: 100%;"><input type="button" value="Send Reply" title="SendReply" name="SendReply" ng-click="SendReply()"/>

<div><input type="text" ng-model="xxx" name="message"/>

<块引用>

umbraco 后台出错:

解决方案

从 URL 中删除Surface"并包含backoffice":

 angular.module("umbraco").controller("Reply.controller", function ($scope, $http) {$scope.SendReply = 函数 () {var sendTo = $("#Email").val();var textMessage = $("#TextMessage").val();$scope.xxx = "我来了!";var data = { SendTo: sendTo, TextMessage: textMessage };//~/Hello2Surface/ReplyMessage --->找不到这个网址$http.post("backoffice/Reply/Hello/ReplyMessage")//找不到这个网址.then(功能(响应){警报(是!");//去做:});}});

此外,我建议使用 UmbracoAuthorizedController 而不是表面控制器,因为登录用户会在后端使用它,因此保持其安全是明智之举.

所以你的控制器应该看起来像这样:

[PluginController("Reply")]命名空间 Jahan.Nuts.Web.Mvc.UmbracoCms.App.App_Plugins.Reply{公共类 HelloApiController : UmbracoAuthorizedJsonController{public [Model-to-be-returned-to-angular] ReplyMessage(){//sql查询等填充模型//返回模型}}}

I've used Umbraco 7.3 in my project. I created a custom data type but when I want to call a Surfacecontroller in here is HelloSurfaceController or Hello2SurfaceController, I got an error in umbraco backoffice that said Request error: The URL returned a 404 (not found):

I studied some articles about routing but I couldn't solve my problem. I don't know that where I did wrong.

How can I solve this problem?

Reply.controller.js:

angular.module("umbraco")
.controller("Reply.controller", function ($scope, $http) {
    $scope.SendReply = function () {
        var sendTo = $("#Email").val();
        var textMessage = $("#TextMessage").val();

        $scope.xxx = "I'm here!";
        var data = { SendTo: sendTo, TextMessage: textMessage };
        //   ~/Hello2Surface/ReplyMessage  ---> Cannot find this URL
        $http.post("~/App_Plugins/Reply/HelloSurface/ReplyMessage") // Can not find this URL
            .then(function (response) {
                alert("YES!");
                //TODO: 
            });
    }
});

SurfaceController

 namespace Jahan.Nuts.Web.Mvc.UmbracoCms.App.App_Plugins.Reply
 {
    public class HelloSurfaceController : SurfaceController
    {
        [HttpPost][ChildActionOnly]
        public ActionResult ReplyMessage()
        {
            //TODO: how should be write this method that be proper for getting data from angularjs?
            return null;
        }
    }
 }

package.manifest

{
propertyEditors: [
    {
        alias: "Send.Reply",
        name: "Send Reply",
        editor:{
            view:"~/App_Plugins/Reply/Reply.html"
        },
    }
]
,
javascript:[
    '~/App_Plugins/Reply/Reply.controller.js'
]
}

Reply.html

<div ng-controller="Reply.controller">
<div style="width: 100%;">
    <input type="button" value="Send Reply" title="SendReply" name="Send Reply" ng-click="SendReply()" />
</div>
<div>
    <input type="text" ng-model="xxx" name="message" />
</div>

Error in umbraco backoffice:

解决方案

remove the "Surface" from the URL and include "backoffice":

 angular.module("umbraco")
    .controller("Reply.controller", function ($scope, $http) {
        $scope.SendReply = function () {
            var sendTo = $("#Email").val();
            var textMessage = $("#TextMessage").val();

            $scope.xxx = "I'm here!";
            var data = { SendTo: sendTo, TextMessage: textMessage };
            //   ~/Hello2Surface/ReplyMessage  ---> Cannot find this URL
            $http.post("backoffice/Reply/Hello/ReplyMessage") // Can not find this URL
                .then(function (response) {
                    alert("YES!");
                    //TODO: 
                });
        }
    });

Also, I'd recommend using UmbracoAuthorizedController not a surface controller as this is being used in the back end by logged in users it'll be wise to keep it secure.

So instead your controller should look something like this:

[PluginController("Reply")]
namespace Jahan.Nuts.Web.Mvc.UmbracoCms.App.App_Plugins.Reply
 {
    public class HelloApiController : UmbracoAuthorizedJsonController
    {
        public [Model-to-be-returned-to-angular] ReplyMessage()
        {
            //sql query etc to populate model
            //return model
        }
    }
 }

这篇关于Umbraco 在后台找不到路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆