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 ...
随机推荐
- LeetCode(3)Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- Spring,Mybatis,Springmvc框架整合项目(第三部分)
一.静态资源不拦截 第二部分最后显示的几个页面其实都加载了css和js等文件,要不然不会显示的那么好看(假装好看吧),前面已经说了,我们在web.xml中配置了url的拦截形式是/,那么Dispatc ...
- C# 反射总结
反射(Reflection)是.NET中的重要机制,通过放射,可以在运行时获得.NET中每一个类型(包括类.结构.委托.接口和枚举等)的成员,包括方法.属性.事件,以及构造函数等.还可以获得每个成员的 ...
- Linux下安装MySQLdb模块(Python)
一.MySQLdb-python模块 https://pypi.python.org/pypi/MySQL-python ` 二.安装依赖包 yum -y install python-devel m ...
- Linux暂停和恢复进程
Linux暂停和恢复进程 kill -STOP 1234 将该进程暂停. 如果要让它恢复到后台,用kill -CONT 1234 (很多在前台运行的程序这样是不行的) 如果要恢复到前台,请在当时运行该 ...
- hdu 1390
#include<stdio.h> int main() { int t,n,a[1001]; scanf("%d",&t); while(t--) { sca ...
- uva 11916 解模方程a^x=b (mod n)
Emoogle Grid You have to color an M x N ( 1M, N108) two dimensional grid. You will be provided K ...
- poj 3692 Kindergarten
Kindergarten Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6956 Accepted: 3436 Desc ...
- Linux性能分析Top
前言 在实际开发中,有时候会收到一些服务的监控报警,比如CPU飙高,内存飙高等,这个时候,我们会登录到服务器上进行排查.本篇博客将涵盖这方面的知识:Linux性能工具. 一次线上问题排查模拟 背景:服 ...
- @Validated注解
参考: https://blog.csdn.net/changerzhuo_319/article/details/55804651