AspNet MVC4 教学-22:Asp.Net MVC4 Partial View 技术高速应用Demo
A.创建Basic类型的MVC项目.
B.Model文件夹下,创建文件:
LoginModel.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace MvcPartialViewTest.Models
{
public class LoginModel
{
public string Name
{
get
{
return "张三";
} }
public string Remark
{
get
{
return "航大学生.";
}
}
public double Score
{
get
{
return 99.12;
}
}
}
}
OtherModel.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web; namespace MvcPartialViewTest.Models
{
public class OtherModel
{
public string Name
{
get
{
return "李四";
} }
public string Remark
{
get
{
return "航小学生.";
}
}
public double Score
{
get
{
return 100;
}
}
}
}
C.创建HomeController.cs文件:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcPartialViewTest.Models; namespace MvcPartialViewTest.Controllers
{
public class HomeController : Controller
{
// GET: /Home/
public ActionResult Index()
{
ViewData.Model = new LoginModel();
return View();
}
public ActionResult GetPartialView()
{
return PartialView("PartialLink");
}
public ActionResult GetPartialView2()
{
return PartialView("PartialDataFromOtherModel", new OtherModel());
}
}
}
C.创建对应的PartialView:
1)PartialLink.cs:
<a href="http://www.sina.com.cn">新浪</a> <a href="http://www.sohu.com">搜狐</a> <a href="http://www.exesoft.cn">行易软件</a>
2)PartialDataFromLoginModel.cshtml:
@using MvcPartialViewTest.Models
@model LoginModel
<h2>@Model.Name</h2>
<h2>@Model.Remark</h2>
3)PartialDataFromView.cshtml:
@model System.Double
<h2>@Model</h2>
4)PartialDataFromOtherModel.cshtml:
@model MvcPartialViewTest.Models.OtherModel <fieldset>
<legend>OtherModel</legend> <div class="display-label">
@Html.DisplayNameFor(model => model.Name)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Name)
</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.Score)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Score)
</div>
</fieldset>
D.创建View文件:
Index.cshtml:
@using MvcPartialViewTest.Models
@model LoginModel @{
ViewBag.Title = "Index";
}
<h2>1.没有參数传递的PartialView</h2>
<h2>@Html.Partial("PartialLink")</h2>
<hr />
<h2>2.直接从LoginModel中获取数据的PartialView</h2>
@Html.Partial("PartialDataFromLoginModel")
<hr />
<h2>3.从View中间接获取LoginModel数据的PartialView</h2>
@Html.Partial("PartialDataFromView", Model.Score)
<hr />
<h2>4.从控制器直接加载分布视图,不再套用主版视图</h2>
<h2>@Html.ActionLink("取得PartView","GetPartialView")</h2>
<hr />
<h2>5.结合上面创建的的Action,使用Html.Action再次加载</h2>
<h2>@Html.Action("GetPartialView")</h2>
<hr />
<h2>6.使用Html.Action,通过Action获取OtherMode数据的PartialView</h2>
<h2>@Html.Action("GetPartialView2")</h2>
E.效果图:
AspNet MVC4 教学-22:Asp.Net MVC4 Partial View 技术高速应用Demo的更多相关文章
- AspNet MVC4 教学-23:Asp.Net MVC4 Display And Editor 模板技术高速应用Demo
A.创建Basic类型的项目. B.在Model文件夹下,创建3个文件: Role.cs: using System; using System.Collections.Generic; using ...
- 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 ...
- 构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作
原文:构建ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后台管理系统(22)-权限管理系统-模块导航制作 最近比较忙,系统难度独步增加,文章的发布速度明显比以前慢了. 由于我们 ...
- ASP.NET MVC4入门到精通系列目录汇总
序言 最近公司在招.NET程序员,我发现好多来公司面试的.NET程序员居然都没有 ASP.NET MVC项目经验,其中包括一些工作4.5年了,甚至8年10年的,许多人给我的感觉是:工作了4.5年,We ...
- Asp.Net MVC4 + Oracle + EasyUI 学习 第二章
Asp.Net MVC4 + Oracle + EasyUI 第二章 --使用Ajax提升网站性能 本文链接:http://www.cnblogs.com/likeli/p/4236723.html ...
- SignalR + KnockoutJS + ASP.NET MVC4 实现井字游戏
1.1.1 摘要 今天,我们将使用SignalR + KnockoutJS + ASP.NET MVC实现一个实时HTML5的井字棋游戏. 首先,网络游戏平台一定要让用户登陆进来,所以需要一个登陆模块 ...
- ASP.NET MVC4+EasyUI+EntityFrameWork5权限管理系统——菜单模块的实现(二)
ASP.NET MVC4+EasyUI+EntityFrameWork5权限管理系统——数据库的设计(一) 菜单和模块是在同一个表中,采用的是树形结构,模块菜单表结构如下代码: USE [Permis ...
- ASP.NET MVC4中调用WEB API的四个方法
http://tech.it168.com/a2012/0606/1357/000001357231_all.shtml [IT168技术]当今的软件开发中,设计软件的服务并将其通过网络对外发布,让各 ...
随机推荐
- 转:C++:从子类访问父类的私有函数
众所周知,c和c++的数组都是不安全的,因为无论c还是c++都不提供数组边界检查功能,这使得数组溢出成为可能.从某个意义上说,c和c++是一种缺少监督的语言,然而这也正是其魅力所在.c++给予程序员更 ...
- 基于visual Studio2013解决C语言竞赛题之0408素数
题目 解决代码及点评 判断一个数是不是素数的方法,一般是看n是不是能被n以内的某个整数(1除外)整除 为了提高效率,这个整数范围一般缩小到n的平方根 如果在这个范围内的整数都不能整除,那么 ...
- [Django实战] 第9篇 - 表单、视图、模型、模板的交互
本章通过实现一个用户提交任务请求的页面,讲述表单.视图.模型.模板间的交互. 首先,我们需要定义一个表单(forms.py) class CreatetaskForm(forms.Form): cre ...
- 一道TOPK问题
今天遇到一道TOP k的变形题,题目大概意思是有10W个随机整数,然后对这些数进行如下操作: 1.当能被3整除时,将此数替换为此数和其它数两两相加的数,包括数本身 2.当不能被3整除时,将此数替换为原 ...
- exp-00091 oracle错误的解决办法
在进行数据库导入导出使用命令exp.imp经常出现exp-00091 这样的错误的时候,我们需要做的是对于环境变量NLS_LANG设置正确 首先,我们先查看需要导出的数据库的字符编码 selec ...
- 【Nginx】启动报错-端口被占用
将下载的windows版nginx的压缩包nginx-1.4.2.zip解压到F:\server\nginx-1.4.2里面. dos命令键入: F: cd F:\server\nginx-1.4.2 ...
- php 学习笔记 数组2
10.切割数组 array_slice(array, offset, length);返回一个由原始数组中的连续元素组成的新数组,参数1为原始数组,参数2为要复制的起始位置, 参数3要复制的个数:新数 ...
- form验证及图片上传
form验证及图片上传 这一节增加推荐图书的提交和删除功能,来学习node的form提交以及node的图片上传功能.开始之前需要源码同学可以先在git上fork:https://github.com/ ...
- oracle数据库连接无响应的解决
昨天中午时,查询到服务器的数据流水最晚记录是早上8点的,现场查看服务日志很奇怪,日志输出显示挂死在数据库连接这一步.多次调试无果,随后百度发现有资料显示oracle 10.2.1的版本有登录无响应的B ...
- 基于visual Studio2013解决算法导论之048红黑树
题目 红黑树 解决代码及点评 // 红黑树.cpp : 定义控制台应用程序的入口点. // #include <stdio.h> #include <stdlib.h> ...