Friday, November 6, 2009

MVC Hello World

Now we're going to introduce the first MVC application: "Hello World".
What do you need to start:

I will use Visual studio 2008 sp1, so let's get started.

  1. After installing the framework open visual studio and select File>New>Project then from the left tab select web then from the right tab select ASP.NET Web Application

  2. Now from the debug menu choose start without debugging or Press ctrl+f5 to see how the application looks like.


  3. Now back to visual studio look at the solution explorer, it should be like this


  4. Now let's examine these folders:
    1. We have the Content folder which contains Site.css file that defines the initial styles for the website
    2. We have the Controllers folder that contains HomeController.cs which
      contains the code for the default view and HomeController.cs which contains the
      code for managing the login process and new user registeration.
    3. An empty Models folder
    4. We have Scripts folder that contains several javascript files (JQuery and Ajax
      files).
    5. We have the Views folder that contains subfolders containing the index page
      (Home page) and the login and registeration pages.
    6. Finally we have a default.aspx and Global.asax file and web.config file.
  5. For the sake of demonstration we're going to delete the following


  6. Now Back to HomeController.cs replace the code with the following:
    public string Index()

    {
    return "Hello World";

    }
  7. Build and run you should see something like that

  8. Now you have created your first MVC Hello World application

No comments:

Post a Comment