A. Create A basic type project.
Create 4 class files under the B.model directory:
Teacher.cs:
Using system;using system.collections.generic;using system.linq;using system.web;namespace MvcViewModelTest.Models{ Public class Teacher {public string Name { get { return ' Miss Ma '; } } public string Remark { get { return ' computer teacher '; } }}}
Student.cs:
Using system;using system.collections.generic;using system.linq;using system.web;namespace MvcViewModelTest.Models{ Public class Student {public string Name { get { return ' Zhang San '; } } public string Remark { get { return "e-commerce Student";}} }
AllPersons.cs:
Using system;using system.collections.generic;using system.linq;using system.web;namespace MvcViewModelTest.Models{ Public class Allpersons {public Teacher tea=new Teacher (); Public Student stu=new Student ();} }
Other.cs:
Using system;using system.collections.generic;using system.linq;using system.web;namespace MvcViewModelTest.Models{ public class other {public string Name { get { return ' John Doe '; } } public string Remark { get { return ' logistic staff '; } }}}
C. Create HomeController.cs:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using Mvcviewmodeltest.models;namespace mvcviewmodeltest.controllers{public class Homecontroller:controller { //// GET:/home/public actionresult Index () { viewbag.other = new Other (); Return View (New Allpersons ());}}}
d.view/home/Create 1 files:
Index.cshtml:
@using Mvcviewmodeltest.models@model allpersons@{viewbag.title = "Index"; }E::
The AspNet MVC4 teaching -25:asp.net MVC4 Strength type View and other technologies quick comparison Demo