Here we will learn step by step process to create simple hello world applicaiton program in asp.net mvc with example.
To create hello world example in asp.net mvc lets start with creating new ASP.NET MVC application. For this hello world example in asp.net mvc we are using Visual studio 2012.
Click on New Project if you getting started with Start Page. Otherwise you can go from Menu by selecting File àNew àThen select Project.
After that you will see new dialog will pop up for selecting your Template and Project type. From Templates select Visual C# inside that select Web and then project type select ASP.NET MVC 4 Web Application and here we are giving name as “Tutorial1” then finally click on ok button.
After that a new dialog will pop up for selecting Project Template in that select Basic template and from view engine we will choose Razor and then click on ok button.
After create application our basic asp.net mvc application project structure will be like as shown following image.
Here we will learn simple “Hello world” example in asp.net mvc for that let’s start with adding controller with name Home. For adding Controller just Right click on Controller folder then select Add from List inside that select Controller.
After selecting a new dialog will pop up for asking Controller name and Template. Here we will give controller name as HomeController and in template we will select Empty MVC Controller and click on Add button. Once we add our controller that will be like as shown following image
Now we just need to add view for the controller (HomeController) whatever we added in our application. Open our HomeController file and just right click in inside controller anywhere like as shown following image
After Clicking on Add view a new dialog pop up will open for view configuration like as following image
Here we will provide View name as Index and click on Add button once we add view our Project structure will be like as shown following image
Now open our Index view and write message "Hello world" like as shown following image
After adding message on view now let’s save application and run it. For running we must provide URL to it such as Home/Index. Generally our url formats will be like "Localhost:anyport/Controller name/Action result name"
e.g. http://localhost:12024/home/index
Once we run application our asp.net mvc application simple hello world output will be like as shown below