2012-01-17 1 views
8

asp.net mvc3에서 프로젝트를 빌드하려고 할 때.오류 형식 또는 네임 스페이스 이름 'Controller'를 찾을 수 없습니다 (사용 지시문 또는 어셈블리 참조가 누락 되었습니까?)

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 

UPDATE

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 
+0

System.Web.MVC 및 System.Web.Mvc.Controller를 포함했는지 확인하십시오. 실수로 MVC 네임 스페이스 – Devjosh

+0

에 대한 using 절을 제거하지 않았는지 확인하십시오.이 경우 컨트롤러 –

+0

을 인식 할 수 없으면이 링크를 참조하십시오. if http://stackoverflow.com/questions/6238295/the-type-or-namespace-name-servicecontroller-could-not-be-found @dmitry – Devjosh

답변

4

using System.Web.Mvc.Controller;을 제거 여기

하나의 예입니다 MVC의 관련 클래스가 존재 해달라고 말, 나타나는 27 오류 .

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

namespace Controllers 
{ 
    public class HomeController : Controller 
    { 
     public ActionResult Index() 
     { 
      return View(); 
     } 

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

은 또한 프로젝트에서 참조 System.Web.Mvc 조립이 있는지 확인하십시오 : USING 절은 네임 스페이스가 아닌 클래스를 정의하는 데 사용됩니다.

조심해야 할 또 다른 사항은 네임 스페이스입니다. namespace AppName.Controllers 대신 namespace Controllers을 사용하고 있습니다. namespace Controller (s 제외)이 프로젝트에서 어딘가에 정의되어있어 여기에서 사용하려는 Controller 클래스와 충돌 할 수 있습니다.

+0

사실, 내가 참조를 추가하려고하면 System.web.mvc 참조를 찾을 수 없습니다 –

+1

@ DmitryMakovetskiyd, ASP.NET MVC 3을 설치 했습니까? 또한 .NET 4.0 클라이언트 프로파일이 아닌 전체 .NET 4.0을 대상으로하고 있는지 확인하십시오. –

17

프로젝트 참조에 System.Web.Mvc을 추가해야합니다. 참고 문헌에

  1. 마우스 오른쪽 단추로 클릭
  2. 클릭 "참조 추가 ..."
  3. 어셈블리 > 프레임 워크
  4. 검색 어셈블리 (Ctrl 키 + E)를 System.Web.Mvc 위해 (당신 것 아마 더 많은 것 : 버전 2/3/4)
+0

System.Web.Mvc의 이전 참조를 삭제하고 솔루션을 다시 작성한 후 위의 언급 프로세스를 통해 다시 추가하면이 기능이 작동합니다. – Jamil

7

오늘 같은 유형의 오류가 발생했습니다. MVC 버전 3을 설치했고 프로젝트에 오류가 발생하여 이전에 오류없이 실행되고있었습니다. 오늘 제가 한 것은 Windows 업데이트가 자동으로 완료되었습니다. 해당 업데이트에서 MVC 버전 3 업데이트가 자동으로 다운로드되어 설치되었다. 따라서 MVC 버전 3 참조 (이전에 프로젝트에 추가 된 버전)는 Windows 업데이트를 설치 한 후에 더 이상 유효하지 않았습니다. 그래서, 그 참조를 삭제하고 동일한 참조를 추가했습니다. 내 오류가 수정되었습니다. :)

-1

당신은 당신이 솔루션의 테스트 프로젝트가 보인다 Add Reference-> Extentions -> System.Web.Mvc

1

이를 얻을 것이다. 두 가지 방법으로 이러한 오류를 해결할 수 있습니다.

1) 솔루션 테스트 프로젝트를 솔루션에서 제외하십시오.

2) MVC 프로젝트의 참조를 테스트 프로젝트에 추가하기 만하면됩니다. 단위 테스트 프로젝트로 이동> 참조를 마우스 오른쪽 버튼으로 클릭하고 참조 추가를 클릭 한 다음 프로젝트 탭을 클릭하십시오> 프로젝트 참조 추가

여기 가세요!

관련 문제

 관련 문제