简体   繁体   English

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

[英]Error when returning partial view to ajax

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找到对象并填充模型之后,我尝试将partial返回到对话框的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... 现在,像往常一样,遵循将视图放在与控制器同名的文件夹中的标准协议,我看到Visual Studio中的下划线视图名称,所有看起来都很好 - 它找到了文件......

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: 我的文件夹结构:

在此输入图像描述

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. 如果需要,很高兴提供额外的细节,请评论。

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);

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

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