i

ASP.Net A Complete Guide

Strongly-Typed Views [Add images here from the visual studio]

In MVC has provided the different ways to pass data to a controller to view and from View to controller by using the videdata, viewbag, and tempdata. Those ways are the loosely-typed views that send the data. Strongly typed means passing the model object as a parameter to the View. As shown in below example:

public class HomeController: Controller

    {

        public ActionResult Details()

        {

            Employee employeeBL = new Employee();

            Employee employee = employeeBL.GetEmployeeDetails(101);

            ViewBag.Header = "Employee Details";           

            return View(employee);

        }

    }

 

In above example we are passing object as parameter to View. Here in view side (Details.cshtml) we need to specify the "@model" directive for making it as strongly typed view.

@model StrognlyTypedDemo.Models.Employee

cshtml files code will look somewhat like below:

Employee Details

Employee ID: @Model.EmployeeId
Name: @Model.Name

 

 

 

 

In the above example, "EmployeeId" and "Name" are both the properties of the Employee class.