A.创建Basic类型的项目.

B.在Model文件夹下,创建3个文件:

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;
using System.Web.Mvc; namespace MvcEditorTemplatesTest.Models
{
public class Teacher
{
public string TeacherId
{
get
{
return "8888";
}
}
public string FirstName { get; set; }
public string LastName { get; set; }
public Role Role
{
get
{
return Role.Guest;
}
set
{
;
} }
} }

Student.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace MvcEditorTemplatesTest.Models
{
public class Student
{
public int StudentId
{
get
{
return 88;
}
set
{
;
}
}
public string Remark
{
get
{
return "航大学生.";
}
set
{
;
}
}
public Role Role {
get
{
return Role.User;
}
set
{
;
} }
}
}

C.创建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());
}
public ActionResult StudentDetails()
{
return View(new Student());
}
public ActionResult TeacherDetails()
{
return View(new Teacher());
}
}
}

D.创建View:

在Shared以下创建目录:EditorTemplates,然后在当中再创建两个文件:

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("", "比文字来自String编辑模板", new { style = "background:blue;width:220px" })

在Shared以下创建目录:DisplayTemplates,然后在当中再创建两个文件:

Role.cshtml:

@model MvcEditorTemplatesTest.Models.Role
<div id="MyDDL">
@Enum.GetName(Model.GetType(),Model)
</div>

String.cshtml:

@model System.String
@Html.LabelFor(m=>m,Model,new { style = "background:red;width:220px" })

在Home以下创建4个文件:

Index.cshtml:

@model MvcEditorTemplatesTest.Models.Teacher

@{
ViewBag.Title = "Index";
} <h2>Index</h2> @using (Html.BeginForm()) {
@Html.ValidationSummary(true) <fieldset>
<legend>Teacher</legend> <div class="editor-label">
@Html.LabelFor(model => model.TeacherId)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.TeacherId)
@Html.ValidationMessageFor(model => model.TeacherId)
</div> <div class="editor-label">
@Html.LabelFor(model => model.FirstName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FirstName)
@Html.ValidationMessageFor(model => model.FirstName)
</div> <div class="editor-label">
@Html.LabelFor(model => model.LastName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.LastName)
@Html.ValidationMessageFor(model => model.LastName)
</div> <div class="editor-label">
@Html.LabelFor(model => model.Role,"下面界面来自Role模板")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Role)
@Html.ValidationMessageFor(model => model.Role)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<p>
@Html.ActionLink("Go to get Teacher Details", "TeacherDetails")
</p>
<p>
@Html.ActionLink("Go to Create Student","Student")
</p>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

Student.cshtml:

@model MvcEditorTemplatesTest.Models.Student

@{
ViewBag.Title = "Student";
} <h2>Student</h2> @using (Html.BeginForm()) {
@Html.ValidationSummary(true) <fieldset>
<legend>Student</legend> <div class="editor-label">
@Html.LabelFor(model => model.StudentId)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.StudentId)
@Html.ValidationMessageFor(model => model.StudentId)
</div> <div class="editor-label">
@Html.LabelFor(model => model.Remark)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Remark)
@Html.ValidationMessageFor(model => model.Remark)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Role,"下面界面来自Role模板")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Role)
@Html.ValidationMessageFor(model => model.Role)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
<p>@Html.ActionLink("Go to get Student Details", "StudentDetails")</p>
<p>
@Html.ActionLink("Go to Create Teacher","Index")
</p>
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}

StudentDetails.cshtml:

@model MvcEditorTemplatesTest.Models.Student

@{
ViewBag.Title = "StudentDetails";
}
<h2>StudentDetails</h2>
<fieldset>
<legend>Student</legend>
<div class="display-label">
@Html.LabelFor(model => model.StudentId)
</div>
<div class="display-field">
@Html.DisplayTextFor(model => model.StudentId)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Remark)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Remark)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Role)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Role)
</div>
</fieldset>

TeacherDetails.cshtml:

@model MvcEditorTemplatesTest.Models.Teacher

@{
ViewBag.Title = "TeacherDetails";
} <h2>TeacherDetails</h2> <fieldset>
<legend>Teacher</legend>
<div class="display-label">
@Html.DisplayNameFor(model => model.TeacherId)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.TeacherId)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.FirstName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.FirstName)
</div> <div class="display-label">
@Html.DisplayNameFor(model => model.LastName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.LastName)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Role)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Role)
</div>
</fieldset>

F.在Site.css文件里的末尾添加:

#MyDDL
{
width: 150px;
height: 26px;
background-color: #FF00FF;
}

AspNet MVC4 教学-23:Asp.Net MVC4 Display And Editor 模板技术高速应用Demo的更多相关文章

  1. AspNet MVC4 教学-22:Asp.Net MVC4 Partial View 技术高速应用Demo

    A.创建Basic类型的MVC项目. B.Model文件夹下,创建文件: LoginModel.cs: using System; using System.Collections.Generic; ...

  2. AspNet MVC4 教学-27:Asp.Net MVC4 自己定义helper及function的高速Demo

    A.创建Basic类型项目. B.创建App_Code目录,在里面创建2个cshtml文件: MyHelper.cshtml: @helper MyTruncate(string input, int ...

  3. AspNet MVC4 教育-28:Asp.Net MVC4 Ajax技术部门四舍五入余速Demo

    A.创建一个Basic项目类型. B.于Models创建一个文件夹: DivModel.cs: using System; using System.Collections.Generic; usin ...

  4. SignalR + KnockoutJS + ASP.NET MVC4 实现井字游戏

    1.1.1 摘要 今天,我们将使用SignalR + KnockoutJS + ASP.NET MVC实现一个实时HTML5的井字棋游戏. 首先,网络游戏平台一定要让用户登陆进来,所以需要一个登陆模块 ...

  5. 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作

    原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作 最近比较忙,系统难度独步增加,文章的发布速度明显比以前慢了. 由于我们 ...

  6. Asp.Net MVC4 + Oracle + EasyUI + Bootstrap

    Asp.Net MVC4 + Oracle + EasyUI + Bootstrap --操作数据和验证 本文链接:http://www.cnblogs.com/likeli/p/4234238.ht ...

  7. ASP.NET MVC:利用ASP.NET MVC4的IBundleTransform集成LESS

    ASP.NET MVC:利用ASP.NET MVC4的IBundleTransform集成LESS 背景 LESS确实不错,只是每次写完LESS都要手工编译一下有点麻烦(VS插件一直没有安装好),昨天 ...

  8. 如何构建ASP.NET MVC4&JQuery&AJax&JSon示例

    背景: 博客中将构建一个小示例,用于演示在ASP.NET MVC4项目中,如何使用JQuery Ajax. 步骤: 1,添加控制器(HomeController)和动作方法(Index),并为Inde ...

  9. ASP.NET MVC4入门到精通系列目录汇总

    序言 最近公司在招.NET程序员,我发现好多来公司面试的.NET程序员居然都没有 ASP.NET MVC项目经验,其中包括一些工作4.5年了,甚至8年10年的,许多人给我的感觉是:工作了4.5年,We ...

随机推荐

  1. cocos2d-x游戏开发(二)之创建第一个项目

    配置好开发环境之后,尝试创建一个cocos项目 (1)打开cocos2d-x安装目录,如D:\DIY\cocos2d-x-3.3 看到目录下有可执行文件 download-deps 以及 setup ...

  2. C++ STL容器底层机制

    1.vector容器 vector的数据安排以及操作方式,与array非常相似.两者的唯一区别在于空间的运用的灵活性.array是静态空间,一旦配置了就不能改变.vector是动态空间,随着元素的加入 ...

  3. 解决like '%字符串%'时索引不被使用的方法

    解决like '%字符串%'时索引不被使用的方法   分步阅读 解决like '%字符串%'时索引不被使用的方法,如果like以通配符开头('%abc')时索引会失效会变成全表扫描的操作. 工具/原料 ...

  4. json分享

    JSON是什么? JavaScript Object Notation (JSON) is a text format for the serialization of structured data ...

  5. Educational Codeforces Round 26

    Educational Codeforces Round 26 困到不行的场,等着中午显示器到了就可以美滋滋了 A. Text Volume time limit per test 1 second ...

  6. zoj2112 主席树动态第k大 ( 参考资料链接)

    参考链接: http://blog.csdn.net/acm_cxlove/article/details/8565309 http://www.cnblogs.com/Rlemon/archive/ ...

  7. 如何部署 sources and javadoc jars

    mvn org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy-file -Durl=file:///home/me/m2-repo \ - ...

  8. 开源中国+soucetree

    参考链接:http://www.cocoachina.com/programmer/20151012/13682.html 1.创建一个工程

  9. Java 面试参考指南 — 同步

    同步 在多线程程序中,同步修饰符用来控制对临界区代码的访问.其中一种方式是用synchronized关键字来保证代码的线程安全性.在Java中,synchronized修饰的代码块或方法不会被多个线程 ...

  10. UVa10234 Race

    递推,设有i个人排在第一名,剩下的人排在后面,方案有f[i]种,则f[i]=sum(c[n][i]*f[n-i]) 1<=i<=n /*by SilverN*/ #include<a ...