将部分视图返回给ajax时出错

时间:2022-10-08 12:49:13

I have a simple ajax call of a sort I have used many times, like this:

我有一个简单的ajax调用,我已经用过很多次了,像这样:

$.ajax(
            {
                type: "GET",
                url: "/Admin/RolePermission?roleId=" + itemid,
                success: function (result) {
                    $("#dialog-RolePermission).html(result);
                }
            });

And after some standard stuff to find the object by its id and populate a model, i attempt to return the partial to the ajax call for the dialog thus:

在一些通过id查找对象并填充模型的标准内容之后,我尝试返回对话框的ajax调用的部分内容:

return PartialView("_CreateOrEditRolePermissions", bgAll);

Now, as usual, having followed the standard protocol of placing the view in a folder with same name as the controller, I see the view name underlined in Visual Studio and all looks good - it has found the file...

现在,像往常一样,遵循了将视图放置在与控制器同名的文件夹中的标准协议,我看到在visualstudio中下划线的视图名,所有看起来都很好——它找到了文件……

Except I get the following error:

除了我得到以下错误:

The partial view "some view name" was not found or no view engine supports the searched locations...

~/Views/RolePermission/_CreateOrEditRolePermissions.aspx
~/Views/RolePermission/_CreateOrEditRolePermissions.ascx
~/Views/Shared/_CreateOrEditRolePermissions.aspx
~/Views/Shared/_CreateOrEditRolePermissions.ascx
~/Views/RolePermission/_CreateOrEditRolePermissions.cshtml
~/Views/RolePermission/_CreateOrEditRolePermissions.vbhtml
~/Views/Shared/_CreateOrEditRolePermissions.cshtml
~/Views/Shared/_CreateOrEditRolePermissions.vbhtml

This folder structure is working in other situations and I have tried moving the file to the shared folder, and giving a full file path and filetype suffix, like this:

这个文件夹结构在其他情况下也可以工作,我尝试将文件移动到共享文件夹,并给出完整的文件路径和文件类型后缀,如下所示:

return PartialView("~/Views/RolePermission/_CreateOrEditRolePermissions", model);

and this (which for some reason is the "browse to url shown in the file properties):

而这个(出于某种原因是“文件属性中显示的浏览到url”):

return PartialView("~/Admin/RolePermission/_CreateOrEditRolePermissions.cshtml", model);

EDIT:

编辑:

My folder structure:

我的文件夹结构:

将部分视图返回给ajax时出错

I'm sure this must be something simple and there are various questions on here which appear to be have the same issue but the solutions there are not working. Happy to provide extra detail if required, please just comment.

我相信这一定很简单这里有各种各样的问题看起来都有同样的问题但是解决方法都不起作用。如果需要的话,我们很乐意提供更多的细节,请评论。

1 个解决方案

#1


3  

Something wrong with your area usage. Without deep dive, quick and dirty fix may be to use absolute path:

你的区域使用有问题。没有深度的潜水,快速和肮脏的修复可能是使用绝对路径:

return PartialView("~/Areas/Admin/Views/RolePermission/_CreateOrEditRolePermissions.cshtml", model);

#1


3  

Something wrong with your area usage. Without deep dive, quick and dirty fix may be to use absolute path:

你的区域使用有问题。没有深度的潜水,快速和肮脏的修复可能是使用绝对路径:

return PartialView("~/Areas/Admin/Views/RolePermission/_CreateOrEditRolePermissions.cshtml", model);