Getting started with ASP.NET MVC 5

After this relatively short introduction, we will say enough of theory and let’s get our hands dirty with some code.

Today, I will teach you the basics of building an ASP.NET MVC 5 web app and for this purpose, I’ll be using Microsoft Visual Studio 2015 Update 3.

However, we need to check some MVC 5 requirements on your system first:

  • We will need .NET 4.5 Framework, so if you’re running Windows Vista Service Pack 2, Windows 7, 8 or 10 that’s fine because you already have it. Otherwise, you will need to download the framework updates.
  • If you want to work with a server operating system, I advise you to use Windows Server 2008 R2 or Windows Server 2012.

Now, concerning your IDE (Integrated Development Environment), if you are using VS 2013+, congratulation! You have nothing to install, MVC 5 is already there waiting for you to use it.

MVC 5 Application Building:

To create an MVC project, you can either click on New Project from the Start page, or go to the File in menu options and select New Project.

CreateProject1CreateProject2

A New Project window will pop-up, select Visual C# on the left panel, Web and ASP.NET Web Application. In the Name field, write “MVCSchool” and then click OK.

CreateProject3

You will see a new window entitled ASP.NET Web Application window with different sections.

CreateProject4

Let us take some moments to talk about them:

  • Template selection: Allow you to choose from different frameworks. If you remember what I told you about “One ASP.NET”, you will understand that even-though you start your project with a structure type, you can add in support lately for any available frameworks through “Add folders and core references for” section or NuGet package Manager.
  • Add unit tests checkbox: you have the ability to create a unit test project with sample unit tests.
  • Change Authentication button in which you have four options:

          No Authentication for apps that does not need any user authentication.

          Individual User Accounts (selected option) for apps that store user profiles in a SQL Server Db (users can also use the social provider of their choice).

          Work And School Accounts for application that authenticate with Active Directory/MS Azure Active Directory/Office 365.

          Windows Authentication for apps working on premise (locally).

Since we are going to run our application against the local development server, there is no need to check the Host in the cloud checkbox. (For more information about working with Microsoft Azure, you can check this link).

AND VOILA! Thanks to the default template used in Visual Studio for MVC projects, you have a brand new application without doing anything!

CreateProject5

This is a simple “Hello World” application perfect for you to start.

The first page you see is the Project_Readme.HTML, which is a customized file for each application template and contains many useful links.

Now press F5 to launch your application with the default Bootstrap template:

WebAppTemplate

MVC Application Structure:

Go to View menu item, select Solution Explorer you will see a small window, generally on the right side of your screen, which shows the tree structure of your solution. There are eight main directories and a bunch of other files:

ProjectStructure

  • /App_Data: for read/write files.
  • /App_Start: for configuration code to work with Routing, bundling and Web API.
  • /Content: for CSS files, images and other content.
  • /Controllers: where you find Controller classes.
  • /fonts: for Bootstrap custom web fonts
  • /Models: for Classes representing data and business objects.
  • /Scripts: for JavaScript files and scripts.
  • /Views: for files related to rendering output.

Of course, this structure is not unchangeable, you can adapt it according to your projects’ needs. For instance, developers working on large projects tend to split the application through multiple projects to make it more manageable.

That’s it for this post. I hope that you have now a better understanding of the way you can create your ASP.NET MVC Application and how they are structured.

My advice to you is to try to perform the same steps I went through in this tutorial multiple times to get the habit of creating MVC 5 applications.

In my next post, we will see in more details one of the main MVC’s components. Till then take good care.

Goodbye internet!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: