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的更多相关文章

  1. AspNet MVC4 教学-23:Asp.Net MVC4 Display And Editor 模板技术高速应用Demo

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

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

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

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

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

  6. Asp.Net MVC4 + Oracle + EasyUI 学习 第二章

    Asp.Net MVC4 + Oracle + EasyUI 第二章 --使用Ajax提升网站性能 本文链接:http://www.cnblogs.com/likeli/p/4236723.html ...

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

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

  8. ASP.NET MVC4+EasyUI+EntityFrameWork5权限管理系统——菜单模块的实现(二)

    ASP.NET MVC4+EasyUI+EntityFrameWork5权限管理系统——数据库的设计(一) 菜单和模块是在同一个表中,采用的是树形结构,模块菜单表结构如下代码: USE [Permis ...

  9. ASP.NET MVC4中调用WEB API的四个方法

    http://tech.it168.com/a2012/0606/1357/000001357231_all.shtml [IT168技术]当今的软件开发中,设计软件的服务并将其通过网络对外发布,让各 ...

随机推荐

  1. java如何把char型数据转换成int型数据(转)

    一字符串,String=“2324234535”:把第i个数取出来时是char型的:char temp=String.charAt(i)如何把char型转换成int型?我需要求个尾数之和,如:123的 ...

  2. Eclipse 取消import自动补全具体的类名

    有时候,在代码里写了一个JFrame,然后Eclipse就自动添加了import javax.swing.JFrame; 但有时候希望只要import javax.swing.*;就可以了,不希望具体 ...

  3. Ubuntu12.04 cuda5.5安装

    预处理步骤: 首先确认你的电脑装了一个可以运行CUDA程序的GPU. lspci | grep -i nvidia 另外要确认linux版本和gcc版本 具体参考链接:http://docs.nvid ...

  4. C 语言统计关键字出现次数

    #include <stdio.h> #include <ctype.h> #include <string.h> #define NKEYS (sizeof ke ...

  5. Ubuntu 13.04 安装使用clang

    其实很简单,就是用命令即可: apt-get install clang-3.2 clang-3.2-doc 主要说明一点,/usr/bin/c++链接原来指向g++,现在被改变了. $ ls /us ...

  6. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  7. 【Web】HttpServletRequest request 相关方法 得到路径

    username=qqqq password=wwww //----------------------POST-------------------> http://192.168.1.211 ...

  8. 写一方法来实现两个变量的交换。在主调函数中定义两个整型变量,并初始化,调用交换方法,实现这两个变量的交换。(使用ref参数)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. 【转】centos安装memcached+php多服务器共享+session多机共享问题

    参考博文: centos安装memcached 源码安装 Yum安装Memcache Memcached内存分配优化及使用问题 <转>php+memcached 实现session共享 P ...

  10. sed学习笔记整理

    1.sed简介 sed (Stream Editor)是一种在线编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处 ...