Adding asp.net.mvc to ASP.NET: Controllers folder
I have an ASP.NET application and I am trying to turn this into an ASP.NET/ASP.NET.MVC 4.0 hybrid application.
I tried to create a folder named "Controllers" and put the .cs file there:
public class PlayerGroupController : Controller
{
public PlayerGroupController()
{
}
public string Index()
{
return "Hello World!";
}
public ActionResult LayoutTemplates()
{
return View();
}
}
Any attempt to access "PlayerGroup / LayoutTemplates" doesn't work (just get "Not Found" error)
Then I moved that file to App_Code
and it works fine. I'm glad that something works for me, but I'd rather follow the convention of the controller classes found in the folder named Controllers
.
Is there some magic setting that I can set somewhere to start recognizing Controllers
as a code folder?
source to share
If the project is configured as a website project, all code files (* .cs) must be in ~ / App_Code or their subfolders. If the project is a web application project, the code files can be moved anywhere in the project and compiled by VS into a DLL that goes into the ~ / bin directory, which is then loaded by ASP.NET.
MVC is specifically geared towards a Web Application (WAP) project, so I recommend creating a new WAP and copying all files into it, then navigating from there.
source to share