Getting Started with ASP .Net MVC5

There are a lot of website options right now. You can hand code an HTML5 page, you can use Word Press, PHP, or even go to a WYSIWYG (what you see is what you get) service. I have decided learn a Microsoft technology, MVC 5.

I am not going deep into the advantages of the technology, but straight into getting starting. I am also not going into the tools that much, Razer, HTML5, and C#. That can be for another day. I will help you get started playing around with the technologies so you can learn these things on your own. The first step is to get the tools. You need to download the latest version of visual studio, http://www.microsoft.com/visualstudio/eng/2013-downloads#d-2013-express. I won’t go into much for visual studio, but there are other great tutorials.

Now we have the tool, we need to create the solution.  A solution is a set of projects and the visual studio template is powerful!

The create solution dialog
The create solution dialog
Selecting the project and including types
Selecting the project and including types

 

 

 

 

 

We want to select an ASP .Net web application (not an MVC 4 application).  Then we only select MVC.  We don’t want to play with the other project types in this tutorial.  Afterwards, you solution explorer should look like this.

New MVC Solution Explorer
New MVC Solution Explorer

Next, we delete the junk we don’t care about.  This is everything in  Models, and Controllers.  Also delete the file Startup.Auth.cs and the folders in Views. As a note, you just deleted the authorization code. For this site, we are not going to talk about auth, everyone can see/use it. Now make sure your solution builds.

Create these data objects
Create these data objects

For my example site, I am making two POCOs.  One for each of my tutorial posts, another for external references.  We are going to use code first development.  You can see from above on the left hand side my two classes. After you create them, build the solution (it makes the next step easier). Then you make your DB context, the top right box. Something new to MVC, you can register your data context.  You want to add to the class Startup the static GetContext method add app.CreatePerOwinContext<AppDataContext>(GetContext); to the Configuration method.  Make sure you build again.

Now we want to add the controllers and views.

Create the Controller and Views
Create the Controller and Views

If you right click in your solution explorer on the controller folder you get several options. You want the view to be generated for you and a class in your model folder as your model class. I also referenced my AppDataConfig data context I created. I kept my _viewstart file, so I did not need to do anything for the layout page. You build on controller per POCO.

At this point, you can actually view you website.  From here, build or do what ever you want to on your new website.

My tutorial page
My tutorial page

 

Leave a Reply

Your email address will not be published. Required fields are marked *