How to implement Route constraints Concepts in mvc application

By // 1 comment:
Route constraints is a way to put some validation rules in a defined route. This is very useful concepts in mvc application.You can apply Route constraints according to your requirements.Your mvc application will be run after performed the validation steps. 
Why does we use it:- 
Any unauthorized user can't access your mvc application. 
Example :-
Suppose we have defined following rules (route path) in your mvc application.If you want to restrict the incoming url with numeric id.then we will have to apply this constraints in your Global.asax file in your mvc application.
1.)  Here first i will show you that there is no restriction in incoming request url as shown below:-

public class MvcApplication : System.Web.HttpApplication
        public static void RegisterRoutes(RouteCollection routes)

                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", 
                    action = "Index", 
                    id = UrlParameter.Optional } // Parameter defaults


2.) Creating Route constraints:- 
Here i will show you "How to create Route constraints in mvc application". Here i will restrict the url parameter with numeric value as shown below:- 

public class MvcApplication : System.Web.HttpApplication
        public static void RegisterRoutes(RouteCollection routes)

                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Bollywood", 
                    action = "Images", 
                    id = UrlParameter.Optional },// Parameter defaults
            new {id =@"\d+"} // Restrict Numeric Id

1.) If you are using example number 1 codes , there is no Route constraints .Means you access any url like
Here you will see no error  message if this image id 10 exists in your  mvc application. 
2.) If you are using  example number 2 codes, here i have putted a Route constraints on Id parameter with numeric value (  new {id =@"\d+"}). Means you can't use numeric value in your URL  like
this URL will show an error message that you can't use numeric value with URL Parameter.
If you want to understand the  Complete Route concepts see here

Difference between ASP.NET Web Form and ASP.NET MVC

By // No comments:
There are some differences between ASP.NET Web Form (ASPX.CS) and ASP.NET MVC application as given below:-
1.) Model :-
  • ASP.NET Web Form uses traditional event driven model.
  • While ASP.NET MVC application uses Pattern based model. 
2.) Page Life Cycle :-
  • ASP.NET Web Form follows a page life cycle concepts.
  • ASP.NET MVC application has no page life cycle concepts.
3.) State Management :-
4.) Syntax :-
  • ASP.NET Web Form uses web forms syntax .
  • ASP.NET MVC uses some default customise syntax such as ASPX engine for  MVC1   and  MVC2 templates, and Razor engine for MVC3 , MVC4 and MVC5 templates.
5.) Control :-
  • ASP.NET Web Form uses server controls on your web page.
  • While ASP.NET MVC uses HTML Helpers for this purpose.
6.) Master Page & Layouts:-
  • ASP.NET Web Form uses Master pages for look and feel of the web page.
  • ASP.NET MVC uses Layouts for look and feel of the web page.
7.) Testing:-
  • In ASP.NET Web Form, Automated testing is more complex.It does not supports Test driven Development(TDD) testing. 
  • ASP.NET MVC application supports Test driven Development(TDD). So here  testing is quite simple.
8.) Support over HTML,CSS ,JAVA SCRIPTS :-
  • ASP.NET Web Form supports limited controls over html ,css ,java script etc.
  • While ASP.NET MVC application provide full support over html ,css ,java script etc.
9.) Good or Bad:-
  • ASP.NET Web Form is good for small level applications but little bad for large applications.It needs limited team size.
  •  ASP.NET MVC is good for large Enterprise level applications.It needs large team size .
 10.) URLs Existence:-
  • ASP.NET Web Form is a file based URLs. Means file names exist in URLs must have a physical existence in the application.
  • ASP.NET MVC application uses URLs Routing concepts. Means URLs are separated in Controllers , actions and others.It is based on Controller, not on Physical file
 11.) Open Source:-
  • ASP.NET Web Form does not follow open source concepts.
  • While ASP.NET MVC application follow open source concepts.
 12.) Design and logic codes:-
  • ASP.NET Web Form are tightly coupled models. Means Design and Logic's codes are present in one file( ASPX.CS ).
  • While ASP.NET MVC are loosely coupled models. Means views and logic are loosely coupled because views and logic's are kept in separate file. 
 13.) Interactive Application :-
  • ASP.NET Web form is strong data access high weight application so it is not helpful to develop an interactive application.
  • ASP.NET MVC is a light weight application .This is best to develop an interactive application.

Difference between ASPX and Razor View Engine in MVC

By // No comments:
There are two View Engines used in .NET Framework.
  1. ASPX/Web Form view engine
  2. Razor  view engine
There are some differences between ASPX View Engine ad Razor View Engine as give below:-
ASP.NET MVC Template:-
  • ASPX/Web Form View Engine is a default view engine for MVC 1 and MVC 2 template.
  • Razor view engine is an advanced view engine which was introduced with MVC 3 Template.Razor view engine is default view engine in MVC 3 template.  It is not language but it is a Markup Syntax .
  • The Namespace for ASPX/Web Form engine is System.Web.mvc.Web Form view engine.
  • The Namespace for Razor view engine is System.Web.Razor
Layout/master page:-
  • We can use master page with ASPX view Engine.
  • We can use Layouts with Razor View engine.
File extensions:-
  • The file extensions used with ASPX view engine are  same as web forms. Ex. .aspx extension is used for views,.ascx extension is used for partial views ,WebUserControl and editor template and .master extension is used for master page layouts.
  • The file extensions used with Razor view engine are .Cshtml (Razor with C#) or .VBhtml (Razor with VB). 
  • In ASPX/ Web Form , we can use WebUserControls (.ascx).
  • But we can't use it with Razor view engine.  
  • ASPX view engine is faster than Razor view engine.
  • Razor view engine is little bit slower than ASPX engine.
  • <% ..%> character is used for writing the ASPX view engine code.                                                   ex.   <%Html.ActionLink ("Login", "login_page")%>                      
  • The character @  uses with Razor view engine.                                                                            ex.  @Html.ActionLink ("SignUp", "Reg_page")
Look and Feel:-
  • ASPX view Engine support design mode, means you can see your page look and feel without running the mvc application.
  • Razor view engine does not support design mode in visual studio,means you can't see your page without running the application.
Cross site Scripting Attacks:-
  • ASPX view engine does not prevent cross-site scripting attacks (XSS Attack).Means any script saved in database will be fired while rendering the web page.
  • Razor view engine prevents the cross -site scripting attacks on web page.It encodes the script before rendering the view.
Testing Features:-
  • ASPX view engine does not support Test Driven Development (TDD) .This is more complex in unit testing.
  • Razor view engine support TDD (Test Driven Development). This is simple in unit testing.
  • ASPX/Web Form syntax are not easy to learn.
  • But Razor syntax are easy to learn and clean than ASPX view engine.
Dependency :-
  • ASPX engine completely depends on System.web.UI.Page class.
  • Razore engine does not depends on System.Web.UI.Page class.

Overview of View Engines in ASP.NET MVC

By // No comments:
 A View Engine is a MVC Subsystem which is responsible for rendering the view into HTML form to the Browser(Chrome,Internet Explorer,Firefox etc.).Initially,mvc 1 and mvc 2   template supports one view engine,that is called ASPX View Engine.  Microsoft introduced new View Engine  for MVC 3 template,that is called RAZOR View Engine. You can learn Namespaces in MVC template .There are two view engines for MVC template which was developed by Microsoft.
  1. ASPX
  2. RAZOR
At this time, ASP.NET MVC supports some open source view engines also. All view engines may not support all version of ASP.NET MVC template.
There are some other view engine also as give below:-
  • Spark
  • Nhaml
  • Hasic
  • NDjango
  • Bellevue
  • Brail etc.
How View Engine Works ?
Each view engine (open source,non open source) has using following components as given below:-
  • View Engine Class :-  This class implements the IViewEngine interface and responsible for locating view templates.You can see this class,when you will develop any  ASP.NET MVC application.
  • View Class :- This class implements the IViewEngine Interface and responsible for combing the template with data from the current context. This convert it to HTML Mark up as a output.
  • Template Parsing engine :- The View Engine parse the template and compiles the view executable code.
Note :-  You can use multiple view engine for your ASP.NET MVC application.
There are some concepts of View Engine in ASP.NET MVC template as give below:-
1.) ASPX :- 
  • This default view engine for MVC 1 and MVC 2 template. 
  • This view engine uses same syntax as web forms uses .
  • It uses file extension (.aspx,ascx,.master etc.) as web forms. 
  • It uses <% %> character for data binding purpose.

<html xmlns="" >
<head runat="server">
   <b> <%= ViewData["title"] %></b>
    <br />
    The current Date and time in your System is: <%= ViewData["Date_Time"] %>

2.) RAZOR :-  
  • Razor View Engine is an advanced view engine ,that was introduced Microsoft in MVC 3 template. 
  • Razor is a default view engine in MVC 3 and MVC 4 template.
  • Razor is a new markup syntax developed by Microsoft.
  •  Razor uses @ character to write the markup syntax.
  • Razor is more compact than other view engine.
  • Razor is a best view engine developed by Microsoft.
  • Razor is more compatible with unit testing.
  • Razor uses less codes to bind the data in mvc template.
  • Razor is very easy and much clean web form syntax. 

    ViewBag.Title = "View1";
<h1>Welcome to</h1>
<h2>MY Frist View:- </h2>
    Your @name, is good and the Date is: @Date_time
3.) Spark :-  
This is an open source view engine for ASP.NET MVC template.

4.) NHaml :-  This is a markup language. It is used XHTML of any web document without using of inline code.It is an abstract description of XHTML.

5.) Bellevue :- In this view engine , data binding codes are separate from HTML markup.

6.) Brail :- This view engine is also used in ASP.NET MVC Template.

7.) NDjango :- This can also be used with ASP.NET MVC template.

8.) Hasic :- This view engine can  use in ASP.NET MVC template

Namespaces in ASP.NET MVC

By // No comments:
We have already learnt about Namespaces in C# in our previous tutorial.Here we will learn namespace in ASP.NET MVC application.The Namespaces,classes and interfaces support the ASP.NET MVC Patterns. System.Web.Mvc assembly is used  for namespaces ,classes and interfaces in ASP.NET MVC pattens.
There are some important namespaces as given below:-
  1. System.Web.Mvc
  2. System.Web.Mvc.Html
  3. System.Web.Mvc.Ajax
  4. System.Web.Mvc.Async
1.) System.Web.Mvc :- 
      This Namespace contains classes,interfaces that support the Mvc Pattern for ASP.NET web application.The namespaces includes classes that represent controllers,controller factories , action result,views,partial views and model binders and much more.
2.) System.Web.Mvc.Html :-
       This namespace contains the classes that help render HTML controls in MVC application.This include classes that support forms input controls,partial views,links and validation.   
3.) System.Web.Mvc.Ajax :-
      This namespace contains classes that support Ajax scripts in ASP.NET MVC application. This namespace includes supports for Ajax settings and Ajax Scripts as well.
4.) System.Web.Mvc.Asnc :-
This namespace contains classes and interfaces that support asynchronous actions in an ASP.NET MVC application

Difference between MVC,MVP and MVVM Architecture in .NET

By // 2 comments:
Presentation patterns helps to resolve the UI Complexity and provide clean and manageable User Interface. 
Presentation patterns are divided in three part:-
  1. mvc
  2. mvp
  3. mvvm
There are different variety of viewable patterns as shown below:-

Why does we shift mvc to mvp or other technology
To improve UI ,we have to focus on these three components:-
  • State management
  • Logic Improvement
  • Synchronization
State Management:-
we always want to maintain the current state of the application.If we want to maintain more than one states at one time then complexity will be  increased. To improve this UI complexity , we need to shift another technology. 
Logic Management:-
Every interface has some Logics such as Text boxes,labels,buttons etc or other UI elements. To improve this logic complexity in application,we have to shift another technology.
It is more important part of any presenter patterns.If your application want to communicate with different application,then complexity of the application will be increased.So we have to adopt new technology to solve this problem in your application.

MVC (Model View Controller)
MVC is a new technology Developed by Microsoft to enhance some features of the ASP.NET web Application. When we are developing large enterprise level application then we have to use MVC or MVP or MVVM technology.It reduces the code complexity of the application.

There are three important concepts in MVC model.
  1.) Model :-  
  • This part represent the data and business logic of the application.
  • This component focus on keeping track of the state of the application.
  • This responsible to how data can be changed and manipulated. 
2.) View :- 
  • This provide the user interface (UI) of the web application.
  • This component is visible to end users who is accessing the application.
  • View represent the UI components like html,css,xml,jquery etc.
 3.) Controller :- 
  • The controller component receive the request via view. After that pass this request to model for processing the user data.
  • The Model component pass the result back to controller. 
  •  The controller is responsible to pass the result to the view.
  • The view display the result on your user interface. 
Some Important point about MVC
  • MVC consists of three components model,view and controller.
  • The model and view created by the controller.
  • Dotted line indicates,view knows about model but model does not know about any other components.
  • Request first comes to controller via view.after that it pass the request to model for manipulation.
  • The helps to bind the model with view.
  • Here Logic is stored in controller. 
MVP (Model View Presenter)
  • The MVP Pattern is an Architecture pattern which is used to build ASP.NET web application.
  • This pattern is similar to mvc pattern.
  • This system is an evolved version of mvc.
  • MVP is the Successor of MVC.
  • MVP pattern is more suitable in UNIT Testing. 

Model and view components are same as mvc components.But Presenter replace the Controller in mvp pattern.
We can categories MVP in two components:-
  1. MVP (SC)
  2. MVP (PV)

1.) MVP (supervising controller pattern):-

There are two variation of MVP Pattern,MVP (SC) and MVP(PV).
  • The view gets the user input and pass it to the presenter.
  • The view and presenter can communicate each other (two way).
  • State is stored in view.
  • The view does not know about presenter.
  • The presenter knows the view.
  • The model does not know about presenter.
  • The view will have the ability to talk directly with model.
  • The presenter component inform the model if any activity has occurred in model.

2.) MVP (passive view pattern):-
  • The view gets the user input and pass it to the presenter.
  • The view and presenter can communicate each other (two way).
  • State is stored in view.
  • Logic is stored in presenter.
  • The Presenter knows the view.
  • The view does not know about presenter
MVVM (Model View ViewModel) :-
MVVM stands for Model View ViewModel. This  support WPF and SilverLight Patterns.This pattern supports two way data binding between View and ViewModel .

Some Key points about MVVM Pattern:-
  • First user interact with view.
  • The view gets the user input and forwards it to the ViewModel by using command. 
  • This pattern support two way data binding between view and view model.
  • The view knows the about ViewModel.
  • The ViewModel does not know about view.
  • The model does not know about ViewModel.
  • Many view can be mapped to one ViewModel.
  • It uses WPF and SilverLight Bindings.
For More...

Routing Concepts of ASP.NET MVC Framework

By // No comments:
ASP.NET MVC Framework works on the concepts of routing to map URLs to the Controller class and Action defined in the Controller.Routing use the Route table for Matching the URL definition according to a pattern in mentioned Route table and passes them as parameter arguments to a controller Action after validation.
ASP.NET application, not using routing concepts.It specifically maps the URL based incoming request to the physical file(ex .aspx file) .
routing table

You can see Routing table codes in your Global.aspx file as given below:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Student_MVC_Application
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit

    public class MvcApplication : System.Web.HttpApplication
        public static void RegisterRoutes(RouteCollection routes)
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Mystudent", action = "Index", id = UrlParameter.Optional } // Parameter defaults

        protected void Application_Start()


Description:- Here you can see following routing elements as given below:-
  • Route Name = Default
  • URL with Parameter = {controller}/{action}/{id}
  • Controller Name = Mystudent
  • Action Name = Index
  • MapRoute and IgnoreRoute are use as extension methods of the RouteCollection class.
  • The MapRoute makes use of the Route Object property and creates an instance of Route.
  • The IgnoreRoute method works with the StopRouteHandler Class.
  • {resource}.axd/{*pathInfo}, is used to prevent requests for the web resources,such as WebReference.axd or ScriptResource.axd ,from getting passed to a controller.
What is Pattern 
A pattern is a signature that helps for matching the Incoming Request to your system or other.
Example :-
{controller}/{action}/{id} is a predefined pattern in every MVC templates.You can change your route Path according to your project using Custom Routing Functionality.
What is the Meaning of this Pattern:-
Suppose you have hosted your MVC Application on server and your domain name is .If you want to open a page that contains images and image id 10 then what will you do? You will find this page through your Browser URL request over the internet.
You will type your request as following way in your browser as given below:- .
Suppose your project definition as follows.
 controller name = Bollywood
action-name =images
Image id=10
Then you will request following URL through browser over internet as given below:-
  • If You want access above information on your local system then it will be like this http://localhost:59279/Bollywood/images/10
  • Remember, Name of controller and action will be case sensitive.
  • Remember one things,Route name can't duplicated in will be unique in whole application.
  List of URLs and its Meaning:-
There are following URLs and its definitions as given below:-
1.)  :- 
Here controller =Home, action=Index ,id =none, since default value of controller and action are Home and Index Respectively.
2.) :-
Here controller =Bollywood, action=Index ,id =none ,since default value of action in Index.
3.) :-
Here controller =Bollywood, action=images ,id=none
4.) :-
Here controller =Bollywood, action=images ,id=10
5.) :-
There is no match found because this pattern route is not defined in Global.asax file .First You have to define a separate route for this URL in Global.aspx file.Then it will work .

Now one question will be  raised in your mind "How to create custom route in ASP.NET MVC application".I will explain it in a separate post.
 For More...
  1. Binding concepts of WPF
  2. How to implement Role based security in application
  3. How to display xml data in list box in application
  4. Advance .net and c# interview questions and answers
  5. How to insert data in ms access database and display it in gridview control
  6. How to save image on website folder in

Difference Between 3-Tier Architecture and MVC Architecture in .NET

By // No comments:
There are lots of students who are facing problems with 3-tier architecture and MVC architecture.Many student confuse in 3-tier architecture and MVC architecture. I have already explained 3-tier architecture and mvc architecture concepts with real life examples.Both are using same concepts but there are some differences their working senorio.
3-Tier Architecture Concepts:-

1.)  3-Tier Architecture separates the application into 3 components as given below:-
  • Presentation Layer (UI)
  • Business Access Layer
  • Data Access Layer
2.)  3-Tier Architecture is a Linear Architecture.
3.)  In 3-tier Architecture, user interacts with Presentation Layer.It is a User Interface layer which can interact to any user in application.
4.)  In 3-tier Architecture, Business Access Layer is Responsible for all communication between Presentation layer and Data Access Layer.Here Business Access Layer is a mediator between Presentation layer and Data Access Layer.
5.)  In 3-tier Architecture,All Data will be stored on Data Access Layer Only. 
6.)  In 3-tier Architecture, Bidirectional communication is possible (with Business layer) within layers (presentation and Data access).

MVC Architecture Concepts:-

1.)  MVC Architecture separates the application into three components as given below:-
  • Model
  • View
  • Controller
2.)  MVC Architecture is a triangular Architecture.

3.) In MVC Architecture , user interacts with View component.
4.) MVC Architecture uses 3-Tier Architecture concepts .
5.) In MVC Architecture, Controller component is responsible for communication between view and model.Ex.If user (View) want to update your database values then it(request) first pass to the Controller component,after that controller pass the request to model component if required.
6.) 3-Tier Architecture and MVC Architecture used together.MVC doesn't replace 3-tier architecture.  
For more...

  1. Namespace in WPF Application with example
  2. How to implement login controls in application with example
  3. PLINQ Concepts in .NET
  4. WPF Architecture Concepts
  5. How to make calculator in visual studio 2010 and install it on your system
  6. Real concepts of Layout control in WPF

How to Create ASP.NET MVC Complete application with Model View and Controller Components

By // No comments:
Hi Friend, Here We will create MVC application with the help of Model ,view and controller components.This components are helpful to create mvc application easily and secure.Here i will show you working of each components with an example. In this tutorial,we will learn "how to pass data from model to controller and vice versa ,as well as how to pass data from controller to view in ASP.NET MVC Framework". Now i am going to to explain this whole concepts on visual studio 2010 with MVC 2 framework. Every MVC Framework(eg. mvc 2 ,mvc 3 ,mvc 4,mvc 5 and mvc 6) can be used to create this simple application. 
There are some steps to implement this whole concepts on your visual studio as given below:-

How to Pass data from Controller to View in ASP.NET MVC Application

By // No comments:
Hi Friend, Here i will show you how to pass data (information) from Controller to View in mvc framework .Here i will use only Controller and View components of the MVC template. We will learn each concepts of MVC one by one from simple level to difficult level. First we shall learn "How to create MVC template in Your visual studio".
  • If you are using visual studio 2008 with sp1 or any or free visual web developers 2008 express with sp1,It's not include MVC 2 by default.You can download ASP.NET MVC 2 template from and install it.
  • If you are using visual studio 2010 any's already include ASP.NET mvc 2 by default.   
  • If you are using Visual studio 2012  or Visual studio  2013 edition, then default template may be changed.but concepts is same for all MVC template (eg. MVC , MVC2 , MVC3 , MVC4.MVC5, MVC6 ) .
There are some steps to implement this concepts in your visual studio as given below:-

How to understand the Concepts of Controller class in MVC Applications

By // No comments:
We have usually developed many applications.But didn't discuss this concepts before.In, user interaction is structured in the sequence of web pages and handles the event of those pages.But In ASP.NET MVC ,user interaction is structured around the controller and action methods.Here ,the Action methods usually have a one to one mapping with user interaction.
The controller classes are the classes that are mapped by the ASP.NET MVC framework URLs.Here,you will see,the controller classes process the incoming request ,tackle the user input and interactions and finally execute the appropriate application logic.The base class for all the controller in controller class which perform MVC handling concepts.
A controller class invokes the a separate view component to generate the HTML Markup for any incoming request. The controller class uses the Icontroller , IActionFilter and IDisposable interfaces .

ASP.NET MVC Framework Real concepts

By // No comments:
The ASP.NET MVC framework is not a substitute for the ASP.NET web forms pattern.It just provide an alter choice to the developer while designing and developing a web application.
The MVC framework resides inside the system.web.mvc namespace. You already know system.web is used for web application. MVC namespace is the part of this namespace.
MVC framework consists of the following components.
  • Model
  • View
  • Controller
Now we will discuss each in detail with an example.

Introduction of MVC

By // No comments:
Nowadays, There are lots of peoples accessing the information from the web.They are accessing the information from different sources like  Laptop,Desktop,Mobile,Tablet,Ipad etc. So Developers should develop those applications who can be viewed on different devices easily. To overcome this problem Microsoft has developed a template that is called  MVC Template.We can view mvc template applications on different devices without facing any problem.
A user Many want to view the static information of a website on a different page,while another user many want to view the same information with some other dynamic content.MVC template can solve this problem.
MVC is a new technology developed by microsoft to enhance some features of application.Therefore,in an application,we may need to create multiple view for a single model.When developing a small application,there is no need to separate data access ,business logic,presentation logic and control codes in an application.But when developing large enterprise level application,interweaving  makes code files more complex,therefore it will be difficult to manage while implementing changes in future. As a result the  implementation ,testing and maintenance efforts are also  duplicated.To reduce this problem,we have to separate the application like
  • Presentation logic
  • Business logic
  • Control logic
Powered by Blogger.