-
Notifications
You must be signed in to change notification settings - Fork 206
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
InvalidOperationException: The view 'Customers' was not found. #47
Comments
You might find the following useful: |
I did manage to get Northwind.Mvc to display the customers for the selected country as indicated in the 7e book. But then I did the tasks in the optional part of the chapter detailed in the GitHub pages. Then after trying out displaying the customers again, I encountered the same unhandled exception of not finding the Customers view in any of the three places indicated. I put a breakpoint in the HomeController.cs code where the HTTpClient is created for Northwind.WebApi. The exception occurred after the response was received from the Northwind.WebApi server (all the customer details were shown on the terminal window for that server). I could only assume that the "model" after being processed by the ".ReadFromJsonAsync<IEnumerable>()" did not somehow fit with the structure of the Customers.cshtml file. I then checked the Customers.cshtml file character by character with the code in the repository compared to my code - to no avail. Eventually I decided to replace the code in my file with the repository version of the Customers.cshtml and Northwind.Mvc.csproj files using cut and paste of the complete files. This seems to have cleared the problem. It may be possible that my Customers.cshtml file may have had some hidden character in it which effectively corrupted the file. This seems to be the only explanation for the exception occurring even though I spent many hours comparing my code with that in the repository. |
Chapter: 15
Page Number: 694
Section Title: Getting customers as JSON in the controller/Starting the web service and MVC client projects
Step Number: 4
Problem to fix: After entering UK in the Select Country box on the Home Web Page
and pressing the associated button to select the appropriate customers. Chrome displays "InvalidOperationException: The view 'Customers' was not found. The following locations were searched:
/Views/Home/Customers.cshtml
/Views/Shared/Customers.cshtml
/Pages/Shared/Customers.cshtml
Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable originalLocations)
Suggested solution:
Other useful information e.g. OS, coding tools, and so on: The following locations were searched:
/Views/Home/Customers.cshtml
/Views/Shared/Customers.cshtml
/Pages/Shared/Customers.cshtml
Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable originalLocations)
Chrome and Visual Studio 2022
All code up to page 694 had been entered as in the book, and runs up to that point had been successful after clearing typos. I've rechecked the code I've entered as against the book. I noted that what appears to be the "missing" view in Northwind.Mvc.Views/Home/Customers.cshtml has at the head of the code:
@model IEnumerable
which may be why the Customers view is not found. However changing "Customer" to "Customers" produces a red squiggle underlining in the code editor suggesting "Customers" is not found in PACKT.SHARED
I have a vague memory that a similar error was encountered earlier and had to be rectified by creating a set from the single-version named table in the database to create an appropriate plural-named collection -- but I can't recall the exact details.
I couldn't find anything in the errata file. I've run the code from the GitHub repository which does work properly, but I've yet to find what I've done wrong in my code and could use some suggestions as to where to find the error.
The text was updated successfully, but these errors were encountered: