首页 文章

命名空间的类型'Mvc'名称空间Microsoft.AspNet中不存在

提问于
浏览
17

我正在Visual Studio 2015中创建一个MVC项目(最初在VS 2013中创建)

这一切都正确构建,但在编码时,视图显示很多错误 .

@{
 ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";

string quoteType = "Fee Estimate";
if (Model.Quote.QuoteType == "QuoteType")
{
}
}

在我的一个视图顶部的代码中,Viewbag,Layout&Model全部带下划线显示错误 .

错误是:

错误CS0103当前上下文中不存在名称“模型”Quilgroup C:\ ,,, \ Index.cshtml 268错误CS0234名称空间“Microsoft.AspNet”中不存在类型或命名空间名称“Mvc”(是你错过了一个程序集引用吗?)Quilgroup C:... \ Index.cshtml 1

我认为开发环境有问题,因为它仍然可以编译并正确运行 .

4 回答

  • 19

    删除%localappdata%\ Microsoft \ VisualStudio \ \ ComponentModelCache文件夹,然后重新启动Visual Studio .

    我有同样的问题,这解决了它 .

    资料来源:After installing AspNet5RC1, can no longer open cshtml files in any previous / new MVC project

  • 0

    这是一个工具问题 . VS 2015仅包含MVC 5.x及更高版本的MVC工具 . 您需要将ASP.NET MVC升级到版本5 .

    换句话说,你的MVC 4.x应用程序仍然可以正确编译和运行,但VS中的开发经验和编辑将不太理想(很多错误如下划线,转到视图都不起作用等)

  • 0

    可能是,您缺少参考包含部分,而模型已被调用而不是模型 .

    *<!--add the refrence, you are missing the reference. this should remove those errors-->*
    @model ManageQuote.Models.Quote
    @{
     ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
    
    string quoteType = "Fee Estimate";
    *<!-- use model instead of Model,I think its what you should be calling here, it would be easy if model classes were known -->*
    if (model.Quote.QuoteType == "QuoteType"){
       }
    }
    
  • 0

    打开项目文件夹搜索* .suo文件删除所有这些文件

    在记事本或记事本中打开.sln文件,然后检查装配路径,它们是否正确映射?如果没有,那么正确映射 .

    然后清除所有临时文件 .

    清理你的代码 . 重建 . 这将解决您的问题 .

相关问题