ASP.Net MVC4, a Walk-Through

This article will provide you a quick introduction to ASP.NET MVC 4 as well as an explanation of how ASP.NET MVC 4 fits into ASP.NET.

Some other major facets of this article are, what's new in ASP.NET MVC 4 and how to determine your development environment to build ASP.NET MVC 4 applications.

Outlines
 
Section 1 
  1. Introduction | MVC4
  2. Layers in MVC
  3. Functionality
  4. MVC 4 | Description
  5. MVC 4 | UI
  6. MVC 4 | Web Framework
Section 2
  1. Dialog Box in MVC
  2. Templates
  3. Razor View Engine
  4. Structure

Introduction to ASP.NET MVC 4


ASP.NET MVC is a fabric for building network applications that use the general and basic Model View Controller pattern for ASP.NET MVC. The ASP.NET framework is connected in some aspects and depend on the functionality.
ASP.NET MVC in ASP.NET

ASP.NET MVC in ASP.NET


ASP.NET came into the light in 2002. At that time it was easy to imagine both ASP.NET and Web Forms together as a single unit or we can say as the same thing. ASP.NET has always supported two layers of abstraction for supporting both the features and some other too, these two layers of ASP.NET framework are as follows.

(I described them as Layer1 and Layer2, it does not mean they are in this specific order.)

System.Web.UI

This is a web form layer that is found in a namespace list. This layer consists of a wide-eyed, clean feel.

System.Web.UI

System.Web

This is the second stratum. This layer provides this set of functionalities:

/System.Web

Functionality

The mainstream method of developing ASP.NET MVC with ASP.NET are:
  • Drag Drop server controls
  • Semi magical states
  • A entire web stack
  • Optimal HTTP web UI
  • Built in web framework

MVC Description


Model View controller (MVC) has been an important architectural pattern in the history of computer science for many years. At the outset, it was known as Thing Model View Editor in 1979. It was later simplified into Model View Controller.

It is a powerful tool, or we can say framework, for classifying the data access logic from display logic by the means of accessing or applying several new and classic functionalities to our applications and web forms as well.

MVC also explicitly separates the concerns and adds a small amount of extra complexity to an application's design, but the extraordinary benefits are also provided by it, that can be easily seen during development.

MVC User Interface (UI)


The following are the 3 major concerns of the user interface:

User Interface

The Model

A Model is a set of classes that are used for describing the data that we are working on/with. It also defines business rules for how the data can be modified and controlled.

The View

The View specifies how the application's UI will be displayed and all the design and view concerns are related to it.

The Controller

A Controller is beside a set of classes like models in general. The primary chore of these divisions is to handle the communication between the user and overall web application.

MVC Web Frameworks


The MVC pattern is frequently used in web programming and applications. With ASP.NET MVC it's based on the following three aspects.

Model

Models are generally a set of classes that define the complete information of the domain you are interested in.

Some operations of this pattern are:

  • Encapsulate stored data
  • Code manipulation
  • Data manipulation
  • DOMAIN Specific business logic

View

A View is a secondary pattern unit, its functionalities are:

  • Generation of HTML code
  • UI display
  • Representation
  • Structure

Controller

A Controller is a special class that handles the relationship between a View and a Model, we can also call it an interface between a View and a Model unit.

ASP.NET MVC 4 Dialog

This dialog box occurs when you create a new ASP.NET MVC 4 application. For these details please visit my article: 

http://www.c-sharpcorner.com/UploadFile/2072a9/creating-a-sample-app-through-asp.net-mvc

MVC specifies options for how the project should be created.

Application Templates

There are several templates available in ASP.NET MVC 4 development work. These templates are as follows:

  • The internet application template
  • The intranet application template
  • The basic template
  • The empty template
  • The mobile application template
  • The web API template

The internet application template 

This contains the beginning of an MVC web application, enough that you can run the application immediately after creating it and see a few pages. The template also includes some basic account management functions that run against the ASP.NET membership system depending on your development work.

The intranet application template

The intranet application template was added as part of the AS.NET MVC 3 tools update. It is similar to an internet application template. But the account management functions run against Windows accounts rather than the ASP.NET membership system.

The basic template

The template is pretty minimal. It still contains:

 
 

Running an application created using the empty template that gives you an error message.
The basic template is intended for experienced MVC developers who want to set up and configure how you want them to be.

The Empty Template

In the most general cases the basic Template is called the Empty Template, but developers have some issues regarding this matter. They complained that:
"It wasn't quite empty enough, with MVC 4, the previous empty template was renamed BASIC and the new Empty Template is about as empty as you can get."

The Mobile Application Template

The mobile application template is re-configured with jQuery mobile to jump-start creating a mobile only website. It includes these most important base structures or we can say the functionalities:

 The Web API Template

The ASP.NET Web API is nothing but a framework for creating HTTP services. The web API template is similar to the internet application template.
Web API functionality is also available in the other MVC project templates and even in non-MVC project types.

Razor View Engine (RVE)

The Razor View Engine is one of the most popular and utilitarian features that existed in MVC 3. Further, it is developed for more advanced functionality in MVC 4.

The razor engine has been the first major update to rendering HTML since ASP.NET 1 shipped almost a decade ago. It was something new that developers were looking for, none at that time was familiar with the fact that this "Razor Engine, that is neither a new language nor a puppet or a framework" will be a trump card of MVC in developing network based applications.

The default view engine used in MVC 1 and MVC 2 for rendering functionality was commonly called the Web Forms View Engine, because it applies the same aspx/ascx/master files and syntax generally used in web courses.

It was planned to support editing controls in a graphical editor or any editor that can be utilized for delivering functionality.

Structure View | RVE

The structural position of a Razor engine is something like:

 
 

(For a more elaborate survey of the Razor View Engine, please proceed through this article link:

http://www.c-sharpcorner.com/UploadFile/2072a9/razor-view-engine-in-mvc-4)
 

MVC Application Structure

When you create a new MVC application with Visual Studio, it automatically adds several files and directories to the project.

These directories are:
 

· /Controllers

It is the directory where you place your controller classes that handle the URL requests. When we expand the controller directory, it shows two sub controller directories:

  • HomeController
  • AccountController

· /Models

It is the directory where you place your classes that represent and manipulate data and business objects. It contains three sub-directories:

  • Account
  • Home
  • Shared

· /View

It is the directory where you place your UI template files that are responsible for rendering output, such as HTML.

· /Scripts

It is the directory where you place your JavaScript library files and scripts.

· /Images

It is the directory where you place your images being used in site.

· /Content

It is the directory where you place your CSS and other site content, other than scripts and images used.

· /Filters

It is the directory where you place your filter code. A Filter is an advanced feature of MVC. It is useful with MVC 4.

· /App_Data

It is the directory where you place your data files, on which you need to perform Read/Write operations.

· /App_Start

It is the directory where you place your configuration code for features like:

  • Routing
  • Bundling
  • Web API
-------------------------------------------------------------------------------
 
For creating a sample MVC CRUD app, please visit this link:
 
 
I hope you will like this. 


Similar Articles