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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With