ASPNET MVC:我在 return JSON ContentResult 方法上收到 "The view X or its master was not found or no view engine..." 错误

ASPNET MVC: I get "The view X or its master was not found or no view engine..." Error on Method that return JSON ContentResult

我有一个方法 return 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>

任何帮助将不胜感激。

提前致谢。

尝试替换:

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

有了这个:

 url:"/Store/Counting/GetUserRoles"

或者确保您有:

url:"/ControllerName/MethodName"

在url

我发现了问题。基本控制器 class 覆盖 OnActionExecuting 方法。并且 if 条件阻止来到这里。

感谢您的所有建议。