To create a simple structure for an ASP.NET MVC site
The simplest for a Hello World.
Some folders are mandatory, such as the Controllers, Models, and Views folders.
I'm using Visual Studio 2013 Express for Web.
Create a new ASP.Net Web Application project:
AddthebasicMVCreferences(Libraries,Global.asax,RouteConfigandetc.)
As a result, you will have a very basic solution. One that if you run F5, will not display any page because there are no pages, but there is the Asp.NET application. Here's how it looks:
Noviews,nocontrols,noscriptfolder(whereweusuallyhavejavascriptfiles)andnoimagefolder,ieno"unnecessary" files.
To create a Hello World with a View
Now you just need to create a new Controller:
AndIusetheMVC5Controller-Empty
See that a controller was created, which I called the DefaultController, very simple:
NowwehaveaControllerwithanactioncalledIndex,butwestillneedtocreateaviewforthisAction.Todothis,justrightclickontheActionIndexandchooseAddView.Fillinthescreenbelow:
As a result you have a cshtml file which is the view of the Index action of the Controller DefaultController.
Nowjuststartthedebug,F5,andyou'llseeabeautifulblankpage.ToincludeHelloWorld,simplywritetheHelloWorldwordintheHTMLoftheIndex.cshtmlfile.
IfIdonotevenwanttocreateaViewformyHelloWorld
IfyoudonotevenwanttohaveaViewfile,youcanchoosetodoaHelloWorldasLaertedemonstratedinyouranswer:
publicstringHelloWorld(){return"Hello World";
}
So, just start the application and navigate to http://localhost:<suaPorta>/Default/HelloWorld