HelloWorld MCV Application


In this article I am going to explain how to create MVC application and what are the main folders in a MVC application. Also I am showing you a basic Hello World MVC application which is very useful for beginners.

If you have done asp.net webforms in visual studio, then this tutorial is very easy for you.

MVC stands for Model View Controller.it is a framework for building web applications using a MVC design:

Model : The Model represents the application core (for instance a list of database records).

View : The View displays the data (the database records).

Controller :The Controller handles the input (to the database records).
The MVC model also provides full control over HTML, CSS, and JavaScript.

mvc architecture

Creating a Asp.Net MVC application in Visual Studio:

Open visual studio --> New Project --> Select Asp.Net MVC 3/4 Web Application. --> give name as HelloWorldMVCApplication --> click OK

create mvc project


Now you have created MVC application. Once you have done this, you can see many folders at right side(in solution).

mvc folders

Then you have to add controller to this project. for this
Right click on Controllers --> Add --> Controller --> name it HelloWorldCOntroller --> click ADD

mvc add controller

after adding the controller open it, you can see a method like this


public ActionResult Index()
{
return View();
}

it is a default method in controller which returns view to the browser.
Now, you have to add View to this controller. for this
Right click on Index() method --> add --> click Add.

mvc add view

Once check your Views folder now. The view which you have just created will be added to this folder.

Open your newly created View file(index.cshtml) and write this

Hello World MVC application



Save your file, and run it. In your browser you will get resource cannot be found error.

This is because we did not set any default page for our application. Once check your browser URL. you will see something like this.

http://localhost:3371/ (3371 is my port number. it might be different for you)

now change it to

http://localhost:3371/http://localhost:3371/HelloWorld (here HelloWorld is the name of our Controller)

Now press enter , then you can see the output of the page we have just created.

This is a basic MVC application for beginners just to give yo the guidance on how to create a MVC application and how to run a MVC webapplication.

Thank you !!


Comments

Author: ranadheer05 Aug 2013 Member Level: Silver   Points : 0

Hi ketan. You are welcome :-)



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: