In this article, we will find and learn the difference between Strongly Typed View vs Dynamically Typed View in ASP.NET MVC. In the previous ASP.NET MVC tutorials, we saw:
Let's Begin: (Dynamic Typed View)
Create a new ASP.NET Web Application.
Select Empty MVC Template and click on OK.
Right click on Models folder and Add Employee Entity class in Model.
Employee.cs Code
Right Click on controller and Add New empty controller and give it a name.
Select Empty MVC Template and click on OK.
Right click on Models folder and Add Employee Entity class in Model.
Employee.cs Code
- public class Employee
- {
- public int ID
- {
- get;
- set;
- }
- public string Name
- {
- get;
- set;
- }
- public string Designation
- {
- get;
- set;
- }
- }
Create an object of Employee model and initialize it property with some data and pass the employee object to the view.
Now add a view for Index Action method of DynamicController. Select Empty Template(without model) as we are going to create Dynamic Typed View.
By default, the model property available within the views is dynamic, which means that we can access the value of Model without knowing its exact type. We can also create a dynamic-typed view by declaring @model dynamic (page as dynamic typed). As we are using dynamic view, Artificial Intelligence doesn't help us and dynamic expression resolved at runtime. If we type or use property that is not present/related to model then an exception is thrown during runtime.
Build and Run the application.
Preview
Strongly Typed View
Let's add another controller and name it as StronglyTypedController and add the same code in Index action method of StronglyTypedController.
Let's add another controller and name it as StronglyTypedController and add the same code in Index action method of StronglyTypedController.
- public class StronglyTypedController : Controller
- {
- public ActionResult Index()
- {
- Employee employee = new Employee()
- {
- ID = 101,
- Name = "Anoop Kumar Sharma",
- Designation = "Software Engineer"
- };
- //Passing the Employee obj to View
- return View(employee);
- }
- }
This time we will select Empty Template. In above example we have selected Empty Template without model class.
Select Employee Model class from the drop-down in order to create a strongly-typed view. Make sure to compile the project before selecting a model class from the dropdown because the list i.e. Model class list in add view dialog populated with the help of reflection.
Add View for Index action method of StronglyTypedController.
@model DynamicVsStronglyTypedView.Models.Employee specifies the datatype for the model. @Model and @model look similar but they are different in reality. @Model is a property of the view that refers to the model that was passed to the view from the controller. Inside strongly-typed view, we get Intelligence and compile time error checking support.
Build and Run the application.
Preview:
Select Employee Model class from the drop-down in order to create a strongly-typed view. Make sure to compile the project before selecting a model class from the dropdown because the list i.e. Model class list in add view dialog populated with the help of reflection.
Add View for Index action method of StronglyTypedController.
@model DynamicVsStronglyTypedView.Models.Employee specifies the datatype for the model. @Model and @model look similar but they are different in reality. @Model is a property of the view that refers to the model that was passed to the view from the controller. Inside strongly-typed view, we get Intelligence and compile time error checking support.
Build and Run the application.
Preview:
I hope you like it. Thanks!
Read more articles on ASP.NET:


naresh kumarPosted Jan 9, 2024, 1:25 PM EST
Great Explanation man this is too easy to understand, Thank You Anoop
Ramakrishna GaddePosted Feb 17, 2017, 3:47 AM EST
Good One on Strongly Typed View vs Dynamic Typed View !!
Delpin Susai RajTOP 100Posted Aug 28, 2016, 7:02 AM EDT
Good article
kalu singh raoPosted Jun 13, 2016, 9:32 PM EDT
Nice Articles
Mohammad KhalidPosted Apr 13, 2016, 10:56 PM EDT
Very good content... Well done....
Anoop Kumar SharmaPosted Apr 7, 2016, 9:06 AM EDT
Thanks MD SHAHWAZ AKHTER Bro..!!
MD SHAHWAZ AKHTERPosted Apr 6, 2016, 9:48 AM EDT
Nice Content bro...
Thiruppathi RPosted Apr 5, 2016, 11:05 PM EDT
Nice Dude...
Jaipal ReddyPosted Apr 5, 2016, 7:55 PM EDT
Nice article
Gowtham KTOP 100Posted Apr 5, 2016, 9:17 AM EDT
Good One
Mohammed IbrahimPosted Apr 5, 2016, 8:26 AM EDT
nice
Debasis SahaTOP 100Posted Apr 5, 2016, 6:23 AM EDT
Nice One..
Vignesh ManiTOP 100Posted Apr 5, 2016, 4:19 AM EDT
Nice
Sthitaprajnya Debasis NayakPosted Apr 5, 2016, 3:19 AM EDT
Nice Article !!!
Humayun Kabir MamunPosted Apr 5, 2016, 2:08 AM EDT
Nice...
Karthikeyan KPosted Apr 5, 2016, 12:47 AM EDT
Good one...Thanks for sharing
Rahul Kumar SaxenaTOP 100Posted Apr 5, 2016, 12:35 AM EDT
Good show