StronglyTypeView in Asp.Net Core
Package
"Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5"
Controllers[Folder]
HomeController.cs
using Microsoft.AspNetCore.Mvc;
using StronglyTypeView.Models;
using System.Collections.Generic;
namespace StronglyTypeView.Controllers
{
public class HomeController : Controller
{
public IActionResult Index()
{
Employee emp1 = new Employee();
emp1.Name = "Ali Khan";
emp1.Gender = "Male";
emp1.Designation = "Manager";
Employee emp2 = new Employee();
emp2.Name = "Usman Khan";
emp2.Gender = "Male";
emp2.Designation = "Assistant";
//It is use for Multiple List
List<Employee> myList = new List<Employee>();
myList.Add(emp1);
myList.Add(emp2);
//Use it for only Single item return View(emp1);
return View();
}
}
}
Models[Folder]
Employee.cs
namespace StronglyTypeView.Models
{
public class Employee
{
public string Name { get; set; }
public string Gender { get; set; }
public string Designation { get; set; }
}
}
Views[Folder]
Home
Index.cshtml
@model StronglyTypeView.Models.Employee
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
<h1> @Model.Name</h1>
<h1> @Model.Gender</h1>
<h1> @Model.Designation</h1>
0 Comments