A. Create a project of the basic type.
B. Under the Model directory, create 3 files:
Role.cs:
Using system;using system.collections.generic;using system.linq;using system.web;namespace mvceditortemplatestest.models{public enum Role { Admin, User, Guest }}
Teacher.cs:
Using system;using system.collections.generic;using system.linq;using system.web;namespace mvceditortemplatestest.models{public class Student {public int StudentID {get; set;} public string Remark {get; set;} Public role role {get; set;}} }
Student.cs:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;namespace mvceditortemplatestest.models{public class Teacher {public int Teacherid {get; set;} public string FirstName {get; set;} public string LastName {get; set;} Public role role {get; set;} } }
C. Create HomeControlller.cs:
Using system;using system.collections.generic;using system.linq;using system.web;using System.Web.Mvc;using Mvceditortemplatestest.models;namespace mvceditortemplatestest.controllers{Public class HomeController: Controller { /// GET:/home/public actionresult Index () { return View (New Teacher ()); } Public ActionResult Student () { return View (New Student ());}}}
D. CREATE VIEW:
Create two files under GKFX:
Role.cshtml:
@model mvceditortemplatestest.models.role<div id= "Myddl" > @Html. dropdownlistfor (M = m, New SelectList ( Enum.getnames (Model.gettype ()), "Guest") </div>
String.cshtml:
@model System.string@html.textbox ("", "I come from a custom String editor template", new {style = "width:220px"})
Create two files under home:
Index.cshtml:
@model mvceditortemplatestest.models.teacher@{viewbag.title = "Index";}
Student.cshtml:@model mvceditortemplatestest.models.student@{viewbag.title = "Student";}
AspNet MVC4 teaching -23:asp.net MVC4 Editor Template Technology Quick Application Demo