Open johntempest opened 1 year ago
If you are getting that error saying that it cannot find /Views/Home/Customers.cshtml
then you either have not completed Step 4, as shown in the screenshot below, or you have created a Razor Page instead of a Razor View.
Did you put a
@page
at the top of the file contents? If so, remove it.
You might find the following useful: https://github.com/markjprice/cs11dotnet7/blob/main/docs/errata/improvements.md#page-533---building-websites-using-aspnet-core
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
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.