The View which Bind with any model is called Strongly Typed View.  You Can bind any class  as model to view

For Binding any Model Class in View we use namespace @using Myproject.Models.ModelClass.

In View. After that you can access property of that model.

Example

First make a model Class

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
namespace MvcApplication1.Models
{
    public class Mindstick
    {
        public string Name { get; set; }
        public string Mobile { get; set; }
        public string Address { get; set; }
    }
}

Then Add Controller and make object of model class inside Index action Method
using MvcApplication1.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
 
 
 
namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
 
        public ActionResult Index()
        {
            Mindstickobj = new Mindstick();
            obj.Name = "Mindstick";
            obj.Address = "Allahabad";
            obj.Mobile = "1234567890";
                       return View(obj);
                      
        }
        public ActionResult About()
        {
            return View();
        }
 
    }
}


Now Add View for action Method Index
@model  MvcApplication1.Models.Emp
@{
    Layout = null;
}
 
<!DOCTYPE html>
 
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
 
    <div>
      @Html.DisplayFor(m=>m.Name);<br />
        @Html.DisplayFor(m =>m.Mobile);<br />
        @Html.DisplayFor(m =>m.Address);<br />
           </div>
 
</body>
</html>

Output




You can also check this helpful link

Strongly Typed View in MVC

  Modified On Nov-30-2017 04:18:16 AM

Leave Comment