Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p587 - Exception because <partial name="_Employee" ... not found #41

Closed
johntempest opened this issue Mar 14, 2023 · 4 comments
Closed

Comments

@johntempest
Copy link

"An unhandled exception occurred while processing the request." Displayed on page localhost:5001/packtfeatures/employees after pressing the button "Contact our employees" on the main page.

Chapter: 13
Page Number: 587
Section Title: Creating a Razor class library
Step Number: 9
Problem to fix: An Exception occurs due to <partial name="_Employee" not found when Northwind.Web is started as per step 3 on page 588
Suggested solution: Change "_Employee" to "Employee" [i.e. remove the underscore character at the start of the string.]
Other useful information e.g. OS, coding tools, and so on: Windows 11, Microsoft Visual Studio 1922
Submitted by John Tempest (john_tempest@blueyonder,co,uk)

Full text of exception as appears on Chrome main window:
An unhandled exception occurred while processing the request.
InvalidOperationException: The partial view '_Employee' was not found. The following locations were searched:
/Areas/PacktFeatures/Pages/_Employee.cshtml
/Areas/PacktFeatures/Pages/Shared/_Employee.cshtml
/Areas/PacktFeatures/Views/Shared/_Employee.cshtml
/Pages/Shared/_Employee.cshtml
/Views/Shared/_Employee.cshtml
Microsoft.AspNetCore.Mvc.TagHelpers.PartialTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)

Stack Query Cookies Headers Routing
InvalidOperationException: The partial view '_Employee' was not found. The following locations were searched: /Areas/PacktFeatures/Pages/_Employee.cshtml /Areas/PacktFeatures/Pages/Shared/_Employee.cshtml /Areas/PacktFeatures/Views/Shared/_Employee.cshtml /Pages/Shared/_Employee.cshtml /Views/Shared/_Employee.cshtml
Microsoft.AspNetCore.Mvc.TagHelpers.PartialTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, int i, int count)
AspNetCoreGeneratedDocument.Areas_PacktFeatures_Pages_Employees.ExecuteAsync() in Employees.cshtml
+

Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, bool invokeViewStarts)
Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable statusCode)
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, string contentType, Nullable statusCode)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|30_0<TFilter, TFilterAsync>(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext<TFilter, TFilterAsync>(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

@markjprice
Copy link
Owner

markjprice commented Mar 14, 2023

The naming convention for shared files like layouts and partial views is to prefix with underscore. Your problem was caused by you naming your file Employee.cshtml instead of _Employee.cshtml. Instead of removing the _ from the <partial> element name, you should add it to the name of the file. The exception you got tells you one of the paths that you should use to find it: /Pages/Shared/_Employee.cshtml

@markjprice
Copy link
Owner

image

@johntempest
Copy link
Author

johntempest commented Mar 14, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants