GP24
GP24

Reputation: 877

Error when returning partial view to ajax

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

$.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:

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...

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

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

EDIT:

My folder structure:

enter image description here

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.

Upvotes: 1

Views: 662

Answers (1)

Dima
Dima

Reputation: 6741

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

Upvotes: 3

Related Questions