MVC Introduction

15 March

                 Entity Framework Code-First

Learn Entity Framework Code-First in simple step-by-step tutorials. These tutorials cover all the features of Entity Framework Code-First starting with the basics of code-first, DB migration, configuring one-to-one, one-to-many and many-to-many relationships with DataAnnotation & Fluent API, and many other features.

Audience:
This tutorial is helpful for beginners who want to learn the Entity Framework Code-First approach from scratch.

Prerequisites:
Basic knowledge of .Net Framework, C#, Visual Studio, and MS SQL Server are required. Also, basic knowledge of Entity Framework would be advantageous.

ASP.NET MVC Folder Structure:

We have created our first MVC 5 application in the previous section. Visual Studio creates the following folder structure for MVC application by default.

MVC Introduction

Let's see significance of each folder.

App_Data:

App_Data folder can contain application data files like LocalDB, .mdf files, xml files and other data related files. IIS will never serve files from App_Data folder.

App_Start:

App_Start folder can contain class files which will be executed when the application starts. Typically, these would be config files like AuthConfig.cs, BundleConfig.cs, FilterConfig.cs, RouteConfig.cs etc. MVC 5 includes BundleConfig.cs, FilterConfig.cs and RouteConfig.cs by default. We will see significance of these files later.
MVC Introduction

Content:

Content folder contains static files like css files, images and icons files. MVC 5 application includes bootstrap.css, bootstrap.min.css and Site.css by default.

MVC Introduction

Controllers:

Controllers folder contains class files for the controllers. Controllers handles users' request and returns a response. MVC requires the name of all controller files to end with "Controller". You will learn about the controller in the next section.
MVC Introduction

fonts:

Fonts folder contains custom font files for your application.
MVC Introduction

Models:

Models folder contains model class files. Typically model class includes public properties, which will be used by application to hold and manipulate application data.

Scripts:

Scripts folder contains JavaScript or VBScript files for the application. MVC 5 includes javascript files for bootstrap, jquery 1.10 and modernizer by default.
MVC Introduction

Views:

Views folder contains html files for the application. Typically view file is a .cshtml file where you write html and C# or VB.NET code.
Views folder includes separate folder for each controllers. For example, all the .cshtml files, which will be rendered by HomeController will be in View > Home folder.
Shared folder under View folder contains all the views which will be shared among different controllers e.g. layout files.
MVC Introduction


Additionally, MVC project also includes following configuration files:

Global.asax:

Global.asax allows you to write code that runs in response to application level events, such as Application_BeginRequest, application_start, application_error, session_start, session_end etc.

Packages.config:

Packages.config file is managed by NuGet to keep track of what packages and versions you have installed in the application.

Web.config:

Web.config file contains application level configurations.

The MVC (Model-View-Controller) design pattern has actually been around for a few decades, and it's been used across many different technologies. Everything from Smalltalk to C++ to Java, and now C Sharp and .NET use this design pattern to build a user interface.
Following are some salient features of the MVC pattern −
  • Originally it was named Thing-Model-View-Editor in 1979, and then it was later simplified to Model- View-Controller.
  • It is a powerful and elegant means of separating concerns within an application (for example, separating data access logic from display logic) and applies itself extremely well to web applications.
  • Its explicit separation of concerns does add a small amount of extra complexity to an application’s design, but the extraordinary benefits outweigh the extra effort.
The MVC architectural pattern separates the user interface (UI) of an application into three main parts
MVC Introduction
  • The Model − A set of classes that describes the data you are working with as well as the business logic.
  • The View − Defines how the application’s UI will be displayed. It is a pure HTML, which decides how the UI is going to look like.
  • The Controller − A set of classes that handles communication from the user, overall application flow, and application-specific logic.

Idea Behind MVC

The idea is that you'll have a component called the view, which is solely responsible for rendering this user interface whether that be HTML or whether it actually be UI widgets on a desktop application.
The view talks to a model, and that model contains all of the data that the view needs to display. Views generally don't have much logic inside of them at all.
In a web application, the view might not have any code associated with it at all. It might just have HTML and then some expressions of where to take pieces of data from the model and plug them into the correct places inside the HTML template that you've built in the view.


The controller that organizes is everything. When an HTTP request arrives for an MVC application, that request gets routed to a controller, and then it's up to the controller to talk to either the database, the file system, or the model..
In this section, we will create a new MVC 5 application with Visual Studio 2013 for Web and understand the basic building blocks of a MVC Application.
First of all, setup a development environment to develop an ASP.NET MVC 5 application
Note : Basic tutorials use MVC 5.2. However, all the basic tutorials are applicable to the previous version aso such as MVC 3.0 & MVC 4.0.

         Development Environment setup:
You can develop ASP.NET MVC application with appropriate version of Visual Studio and .NET framework, as you have seen in the previous section of version history.
Here, we will use MVC v5.2, Visual Studio 2013 for Web Express edition and .NET framework 4.5 to create MVC application.
Download and install Visual Studio Express 2013 for Web-update3. Please check the System requirements to install VS2013

No comments:

Powered by Blogger.