简体   繁体   English

名称“model , html viewdata”在 ASP.NET Core 的当前上下文中不存在

[英]The name 'model , html viewdata' does not exist in current context in ASP.NET Core

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.我正在尝试使用 ASP.NET Core .net 5 开发网站。当我打开 *.cshtml 文件时,我可以看到 Razor 不起作用 - @using、@model 和其他指令无法识别,intellisense 也无法识别工作。 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).从你的错误信息来看,我认为可能是你当前版本的visual studio有问题,缺少某些东西或者一些配置问题(当然,它默认不存在)。

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.您也可以按照第一步中的链接进行学习。

Troubleshooting steps:故障排除步骤:

1. Verify that your vs2019 is normal? 1.验证你的vs2019是否正常?

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 教程:在 ASP.NET MVC Web 应用程序中开始使用 EF Core

在此处输入图片说明

2. Normal operation, then there may be a problem with the configuration of the csproj file in your code. 2.正常运行,那么你的代码中csproj文件的配置可能有问题。

3. If it fails to run and the same error occurs, then it is recommended 3.如果运行失败,出现同样的错误,那么建议

① Upgrade your vs2019 to the latest version. ①将您的vs2019升级到最新版本。

② Go to the project path and delete the .vs folder. ②进入项目路径,删除.vs文件夹。 (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) (因为你刚刚升级了vs2019,可以选择重启确保没有问题,但不是必须的选项)

④ Open the project, rebuild the project, and run. ④ 打开工程,重建工程,运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.net核心中的当前上下文中不存在“程序”这个名称 - The name 'Program' does not exist in the current context in ASP.net core ASP.NET 核心 - 当前上下文中不存在名称“JsonRequestBehavior” - ASP.NET Core - The name 'JsonRequestBehavior' does not exist in the current context ASP.NET - 当前上下文中不存在名称“上下文” - ASP.NET - The name 'Context' does not exist in the current context FluentValidation“错误 cs0103 当前上下文中不存在名称‘x’”.asp.net 核心 2.1 - FluentValidation "Error cs0103 the name 'x' does not exist in the current context" .asp.net core 2.1 ASP.NET Core Web API - 如何解决当前上下文中不存在名称“AddCronJobConfigurations” - ASP.NET Core Web API - How to resolve The name 'AddCronJobConfigurations' does not exist in the current context ASP.NET 核心 Web API - 当前上下文中不存在名称“jsonString” - ASP.NET Core Web API - The name 'jsonString' does not exist in the current context ASP.NET 核心 Web API - 错误 CS0103 当前上下文中不存在名称“FetchToken” - ASP.NET Core Web API - Error CS0103 The name 'FetchToken' does not exist in the current context ASP.NET 核心 Web API - 当前上下文 WebApi 中不存在名称“WebApplication” - ASP.NET Core Web API - The name 'WebApplication' does not exist in the current context WebApi 当前上下文中不存在名称,ApiController,asp.net core,IEnumerable - The name does not exist in the current context, ApiController, asp.net core, IEnumerable 名称“模型”在当前上下文中不存在ASP.NET MVC 4 Razor - The name 'model' does not exist in the current context ASP.NET MVC 4 Razor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM