Reputation: 3258
When compiling, I get this error: The name 'View' does not exist in the current context
in reference to my code return View();
.
Full example code:
namespace Controllers
{
public class FilePageController
{
//
// GET: /FilePage/
public ActionResult Index()
{
return View();
}
}
}
I have done this a couple times and been unable to find an answer on SO, so I wanted to post this along with the answer, in case it helps others who have done the same thing as me while learning MVC.
Upvotes: 63
Views: 41686
Reputation: 89
Upvotes: 2
Reputation: 3258
The controller is not inheriting from the controller
class. MVC does many things by convention, but naming your class with "Controller" on the end is not enough.
Change it to public class FilePageController : Controller
.
By the way, Controller
class inherits from ControllerBase
class. Hence, members of ControllerBase
class are accessible from class inherited from Controller
class.
Upvotes: 122