gpt4 book ai didi

asp.net - 错误 1 ​​找不到类型或命名空间名称 'Controller'(您是否缺少 using 指令或程序集引用?)

转载 作者:行者123 更新时间:2023-12-04 00:05:27 24 4
gpt4 key购买 nike

当我尝试在 asp.net mvc3 中构建项目时。出现27个错误,说mvc相关类不存在:

这是一个例子:

Error   1   The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)    C:\Documents and Settings\hhhhhhhh\my documents\visual studio 2010\Projects\MvcApplication1\MvcApplication1\Controllers\HomeController.cs   10  35  MvcApplication1

更新
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication2.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
ViewBag.Message = "Welcome to ASP.NET MVC!";

return View();
}

public ActionResult About()
{
return View();
}
}
}

错误:
Error   1   The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)    c:\documents and settings\hhhhhhhh\my documents\visual studio 2010\Projects\MvcApplication2\MvcApplication2\Controllers\HomeController.cs   9   35  MvcApplication2

Error 2 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?) c:\documents and settings\hhhhhhhh\my documents\visual studio 2010\Projects\MvcApplication2\MvcApplication2\Controllers\HomeController.cs 11 16 MvcApplication2


Error 3 The name 'ViewBag' does not exist in the current context c:\documents and settings\hhhhhhhh\my documents\visual studio 2010\Projects\MvcApplication2\MvcApplication2\Controllers\HomeController.cs 13 13 MvcApplication2


Error 4 The name 'View' does not exist in the current context c:\documents and settings\hhhhhhhh\my documents\visual studio 2010\Projects\MvcApplication2\MvcApplication2\Controllers\HomeController.cs 15 20 MvcApplication2


Error 5 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?) c:\documents and settings\hhhhhhhh\my documents\visual studio 2010\Projects\MvcApplication2\MvcApplication2\Controllers\HomeController.cs 18 16 MvcApplication2


Error 6 The name 'View' does not exist in the current context c:\documents and settings\hhhhhhhh\my documents\visual studio 2010\Projects\MvcApplication2\MvcApplication2\Controllers\HomeController.cs 20 20 MvcApplication2

最佳答案

您需要添加 System.Web.Mvc到您的项目引用。

  • 右键单击引用文献
  • 单击“添加引用...”
  • 组件 > 框架
  • 中搜索程序集 (Ctrl+E) System.Web.Mvc (你可能会有更多:版本 2/3/4)
  • 关于asp.net - 错误 1 ​​找不到类型或命名空间名称 'Controller'(您是否缺少 using 指令或程序集引用?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8893158/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com