ASPNET MVC:我得到“未找到视图X或其主控或没有视图引擎...”返回JSON ContentResult的方法出错

问题描述 投票:0回答:2

我有一个返回json ContentResult的方法。我从JavaScript文件中调用如下:

 $scope.GetUserRoles = function () {
        $http({
            method: "GET",
            url: Current.VirtualUrl + "Store/Counting/GetUserRoles"
        }).then(function mySucces(response) {
            if (response.data.Status == 1) {
                $scope.UserRoles = response.data.Data;

                $scope.GetCountingList(0, false, "CountingId", "DESC");
            }
            else {
                console.log(response);
                $scope.ShowMessage(msgWarning, msgDataFromServerFail + response.data.Data);
            }
        }, function myError(response) {
        });
    }

在这里调用GetUserRoles方法时不会触发,Response.Data会收到此错误:

<link href="/MySite/Assets/css/pages/error.css" rel="stylesheet" />

    <div class="page-500-full-page">
        <div class="row">
            <div class="col-md-12 page-500">
                <div class=" number">
                    500
                </div>
                <div>
                    <h3>Oops! Something went wrong.</h3>
                    <p>
The view &#39;GetUserRoles&#39; or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Areas/iStore/Views/Counting/GetUserRoles.aspx
~/Areas/iStore/Views/Counting/GetUserRoles.ascx
~/Areas/iStore/Views/Shared/GetUserRoles.aspx
~/Areas/iStore/Views/Shared/GetUserRoles.ascx
~/Views/Counting/GetUserRoles.aspx
~/Views/Counting/GetUserRoles.ascx
~/Views/Shared/GetUserRoles.aspx
~/Views/Shared/GetUserRoles.ascx
~/Areas/iStore/Views/Counting/GetUserRoles.cshtml
~/Areas/iStore/Views/Counting/GetUserRoles.vbhtml
~/Areas/iStore/Views/Shared/GetUserRoles.cshtml
~/Areas/iStore/Views/Shared/GetUserRoles.vbhtml
~/Views/Counting/GetUserRoles.cshtml
~/Views/Counting/GetUserRoles.vbhtml
~/Views/Shared/GetUserRoles.cshtml
~/Views/Shared/GetUserRoles.vbhtml                    </p>
                </div>
            </div>
        </div>
    </div>

任何帮助都感激不尽。

提前致谢。

javascript asp.net-mvc actionresult filecontentresult
2个回答
0
投票

尝试更换:

url: Current.VirtualUrl + "Store/Counting/GetUserRoles"

有了这个:

 url:"/Store/Counting/GetUserRoles"

或者确保,你有:

url:"/ControllerName/MethodName"

在网址中


0
投票

我发现了这个问题。基本控制器类重写OnActionExecuting方法。如果条件阻止来到这里。

感谢您的所有建议。

© www.soinside.com 2019 - 2024. All rights reserved.