Hello to everybody at Stack Overflow and please pardon me if I am missing anything here!
I am studying ASP.NET to prepare myself for an internship. To this end, I am following along with a Microsoft Virtual Academy course entitled "Introduction to ASP.NET Core with Visual Studio 2017".
Specifically, I am watching the video "Routing and MVC", and am now at where Scott H. adds a new folder "Tickets" to "Views" (at the 21:20 minute mark). I have been following his instructions exactly up to this point, and the new index.cshtml
file was created under Views/Tickets
(which I will explain shortly). However, as this screenshot shows, there is a red squiggly line under ViewData
with the associated error
The name 'ViewData' does not exist in the current context
The image shows a total of 8 errors, but I have not made any changes to the file. Neither has Scott in the video up to this point and he is not getting any error with ViewData. What's more, he was able to rename View.cshtml
to index.cshtml
but it does not work for me (hence I used this name when I created my file, and find that renaming to any other string is discarded without any error except those in the error list).
My situation is similar to the one described in this post in that it is already there by default without needing to do anything, so I suspect it could be attributed to how VS2017 has been set up.
UPDATE!!!
I have continued with the video, seeing no runtime error, and am now nearing the end. By 32:20, Scott H. had added this code to the TicketController class:
public IActionResult Index()
{
// GO TO THE DATABASE!
// GET SOME MODELS (STUFF)
var s = new Seat() { Location = "Orchestra" , Price = 300.00 };
return View();
}
public string Index2()
{
return "Hello from Tickets!";
}
Then he modified index.cshtml
to reference using @Model
as such:
@model WebApplication3.Models.Seat
@{
ViewData["Title"] = "index";
}
<h2>My New Tickets View</h2>
@Model.Location for only @Model.Price!
When I enter the same code into my editor the squiggly lines appear under @Model
with the same error as ViewData
:
The name 'Model' does not exist in the current context
Executing the code and navigating to the /tix
page does not show Orchestra for only 300!
on the webpage as shown in the video, but on my side I get this Internal Server Error instead. As before, I have checked my code and it matches what I see in the video.