AspNet MVC4 教学-23:Asp.Net MVC4 Display And Editor 模板技术高速应用Demo
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的更多相关文章
- AspNet MVC4 教学-22:Asp.Net MVC4 Partial View 技术高速应用Demo
A.创建Basic类型的MVC项目. B.Model文件夹下,创建文件: LoginModel.cs: using System; using System.Collections.Generic; ...
- AspNet MVC4 教学-27:Asp.Net MVC4 自己定义helper及function的高速Demo
A.创建Basic类型项目. B.创建App_Code目录,在里面创建2个cshtml文件: MyHelper.cshtml: @helper MyTruncate(string input, int ...
- AspNet MVC4 教育-28:Asp.Net MVC4 Ajax技术部门四舍五入余速Demo
A.创建一个Basic项目类型. B.于Models创建一个文件夹: DivModel.cs: using System; using System.Collections.Generic; usin ...
- SignalR + KnockoutJS + ASP.NET MVC4 实现井字游戏
1.1.1 摘要 今天,我们将使用SignalR + KnockoutJS + ASP.NET MVC实现一个实时HTML5的井字棋游戏. 首先,网络游戏平台一定要让用户登陆进来,所以需要一个登陆模块 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作 最近比较忙,系统难度独步增加,文章的发布速度明显比以前慢了. 由于我们 ...
- Asp.Net MVC4 + Oracle + EasyUI + Bootstrap
Asp.Net MVC4 + Oracle + EasyUI + Bootstrap --操作数据和验证 本文链接:http://www.cnblogs.com/likeli/p/4234238.ht ...
- ASP.NET MVC:利用ASP.NET MVC4的IBundleTransform集成LESS
ASP.NET MVC:利用ASP.NET MVC4的IBundleTransform集成LESS 背景 LESS确实不错,只是每次写完LESS都要手工编译一下有点麻烦(VS插件一直没有安装好),昨天 ...
- 如何构建ASP.NET MVC4&JQuery&AJax&JSon示例
背景: 博客中将构建一个小示例,用于演示在ASP.NET MVC4项目中,如何使用JQuery Ajax. 步骤: 1,添加控制器(HomeController)和动作方法(Index),并为Inde ...
- ASP.NET MVC4入门到精通系列目录汇总
序言 最近公司在招.NET程序员,我发现好多来公司面试的.NET程序员居然都没有 ASP.NET MVC项目经验,其中包括一些工作4.5年了,甚至8年10年的,许多人给我的感觉是:工作了4.5年,We ...
随机推荐
- PyCharm学习笔记(一) 界面配置
通过Ctrl+鼠标滚轮调整字体大小 设置代码区默认字体及大小 设置调试区的字体大小 设置代码风格:如Tab缩进 定义Python模板文件 # @Time : ${DATE} ${TIME} # @ ...
- LeetCode(111) Minimum Depth of Binary Tree
题目 Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the s ...
- Educational Codeforces Round 31- D. Boxes And Balls
D. Boxes And Balls time limit per test2 seconds memory limit per test256 megabytes 题目链接:http://codef ...
- Android自动化测试Uiautomator--UiScrollable接口简介
UiScrollable主要包括以下几个方面的方法: 1.快速滚动 2.获取列表子元素 3.获取与设置最大滚动次数常量值 4.滑动区域校准常量设置与获取 5.先前与向后滚动 6.滚动到某个对象 7.设 ...
- Knockout v3.4.0 中文版教程-13-控制文本内容和外观-css绑定
4. css绑定 目的 css绑定可以给关联的DOM元素添加或移除一个或多个CSS类.该绑定很有用,比如,当一些值为负数时高亮这些值为红色. (注意:如果你不想使用一个CSS类选择器来附加样式而想直接 ...
- Knockout v3.4.0 中文版教程-1-入门和安装
英文原版教程:http://knockoutjs.com/documentation/introduction.html 注:此教程根据英文原版翻译,仅作练习,如有不足或错误,请指正 说明: 对原文中 ...
- Html 前端jinjia2 & ajax
本章内容: jinja2 Ajax中的if语句 参考文档 html可以参照学习:w3school bootstrap学习:bootstrap 综合类学习网站:runoob jinja2学习网站:jin ...
- 使用create datafile... as ...迁移数据文件到裸设备
下面是一个测试过程 1.首先创建裸设备:root@ultra66 # cd /opt/app/oradata/test root@ultra66 # lscontrol01.c ...
- J2EE 中间件 JVM 集群
[转]J2EE 中间件 JVM 集群 博客分类: 企业应用面临的问题 Java&Socket 开源组件的应用 jvm应用服务器weblogicjvm集群 1 前言 越来越多的关键任务和大型应用 ...
- BZOJ 2301 [HAOI2011]Problem b ——莫比乌斯反演
分成四块进行计算,这是显而易见的.(雾) 然后考虑计算$\sum_{i=1}^n|sum_{j=1}^m gcd(i,j)=k$ 首先可以把n,m/=k,就变成统计&i<=n,j< ...