I'm trying to develop a website using ASP.NET Core .net 5. When I open *.cshtml file I can see that Razor doesn't work - @using, @model and other directives are not recognized and intellisense doesn't work. When I hover over model I'm given the error from title:
The name 'model' does not exist in current context
@model IEnumerable<Bookstore.Models.Author>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.name)
</th>
<th>
@Html.DisplayNameFor(model => model.id)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.name)
</td>
<td>
@Html.DisplayFor(modelItem => item.id)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
}
</tbody>
</table>
Judging from your error message, I think it might be a problem with your current version of visual studio, something missing or some configuration problems (of course, it does not exist by default).
The following attempts to solve the steps, all default to the case that there is no problem with your project code, to troubleshoot. You can also follow the link in the first step to learn.
1. Verify that your vs2019 is normal?
According to the following tutorial, download the complete sample code to see if it can run normally.
Tutorial: Get started with EF Core in an ASP.NET MVC web app
2. Normal operation, then there may be a problem with the configuration of the csproj file in your code.
3. If it fails to run and the same error occurs, then it is recommended
① Upgrade your vs2019 to the latest version.
② Go to the project path and delete the .vs folder. (if you can't find it, please open it to allow hidden files to be displayed)
③ Shut down and restart your computer. (because you have just upgraded vs2019, you can choose to restart to ensure that there is no problem, but it is not a necessary option)
④ Open the project, rebuild the project, and run.