简体   繁体   English

ASPNET MVC:我收到“找不到视图X或其主视图或没有视图引擎…”的错误,返回JSON ContentResult

[英]ASPNET MVC: I get “The view X or its master was not found or no view engine…” Error on Method that return JSON ContentResult

I have a method that return json ContentResult. 我有一个返回json ContentResult的方法。 I call on from JavaScript file like this: 我从这样的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) {
        });
    }

When calling here GetUserRoles method doesn't fire and Response.Data get this error : 当在这里调用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> 

Any help will be much appreciated. 任何帮助都感激不尽。

Thanks in advance. 提前致谢。

try replacing: 尝试更换:

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

with this: 有了这个:

 url:"/Store/Counting/GetUserRoles"

or make sure, you have: 或确保您具有:

url:"/ControllerName/MethodName"

in url 在网址中

I found the problem. 我发现了问题。 Base controller class override OnActionExecuting method. 基本控制器类重写OnActionExecuting方法。 And an if condition prevent coming here. 并且如果情况阻止来到这里。

Thanks for your all advices. 感谢您的所有建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM