Here we will learn how to create simple hello world application in asp.net mvc with example.
To create new application in asp.net mvc first open visual studio from Start page select File à New à Project like as shown following image
After that a new dialog pop up will open from that select Templates à Visual C# à Web à In project select ASP.NET MVC 4 Web Application and enter Name of Project “Tutorial3” after this just click on OK button.
Now new ASP.NET MVC 4 Project dialog will appear from that select Basic Template and select view engine as Razor and click OK button like as shown below
Once we click OK button it will create new basic asp.net mvc application that would be like as shown below
Now we will add new controller for adding Controller for that right click on Controller folder à then select Add from List inside that select Controller. Once we select controller new pop up will open in that give controller name as "Default1Controller" and from Template select Empty MVC controller and click on Add button.
After adding Default1Controller you will find a controller with default method name Index of return type ActionResult which will return view() like as shown below. Generally the View is responsible for displaying data and transforming Model or Models to visual representation.
public class Default1Controller : Controller
// GET: /Default1/
public ActionResult Index()
Now let’s add empty View to add view open Default1Controller right click anywhere and select Add View like as shown following image
After Clicking on Add view a new dialog will pop up for view configuration. Here we will keep View name same name as ActionResult name and for creating empty view we will not select Model class here and just click on Add button
After adding you can see an empty View. Here we can add some text in View and just run application to test empty View
For accessing this page type URL like http://localhost: port number / Controller name / View name e.g. http://localhost:42088/default1/index. After typing this URL you will see Index view with message we wrote on it. Now we have completed adding view