Explain me about how we achieve tight coupling view in asp.net MVC.
How we achieve tight coupling view in asp.net MVC?
28828-Jan-2020
Updated on 28-Jan-2020
Home / DeveloperSection / Forums / How we achieve tight coupling view in asp.net MVC?
Explain me about how we achieve tight coupling view in asp.net MVC.
Nishi Tiwari
28-Jan-2020In asp.net mvc model bounded view is a tightly coupled and it is used for creating view. Let’s create tightly coupled View in asp.net mvc application for that first we need to create Model, Controller and View.
Create Model in Asp.Net MVC Application
For creating Model Right click on Models folder then select Add then select Class in asp.net mvc application. After that a new Dialog (Add New Item) will show asking us to enter Class name in which enter name “Person” like as shown below
After adding model now add some properties in this Person class as shown below
Create Controller in Asp.Net MVC Application
Now create simple Controller with name “PersonDetails” for that right click on Controllers folder select Add then Select Controller. Once we select Controller new popup box will open in which mention name as “PersonDetails” and select Template for example Empty MVC controller and click on add after configuring it like as shown
After adding controller we can see default code generated
Now we will change the controller method by adding [HttpGet] attribute to the Action Method and return with new instance Model Person like as shown below
Create View in Asp.Net MVC Application
Now add view for which just right click inside controller and select Add View we will get a popup. Inside this popup we will see default View name and there no need to change that and we are going to use Razor engine that is why we should select Razor engine. In Model class we are going to select Person Model which we have created. In Scaffold template select Create item and click on Add button at last.
After click Add button our View will create which will be tightly coupled to model as shown below
Here red mark border in below is showing view is tightly coupled to person Model.
In this way we can achieve Model bounded view or tightly coupled view in asp.net MVC.