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. Android绘图监听接口OnPreDrawListener详解

    public static interface ViewTreeObserver.OnPreDrawListener 我们先看下API中的定义: 类概述: 为即将绘制视图树时执行的回调函数定义的接口. ...

  2. 一个包含所有c++的头文件的头文件

    #include <bits/stdc++.h> 做CF看见别人用这个函数,然后就能直接用vector,set,string那些函数了,摸不着头脑,感觉特神奇就百度了一下,才发现这个是C+ ...

  3. TCP/IP之DNS域名解析系统

    DNS系统是一个分布式的数据库,当一个数据库发现自己并没有某查询所需要的数据的时候,它将把查询转发出去,而转发的目的地通常是根服务器,根服 务器从上至下层层转发查询,直到找到目标为止.DNS还有一个特 ...

  4. c# datagridviewcomboboxcell值无效的解决办法

    一直认为是数据库存储的数据和datagridviewcomboboxcell对不上导致,今天碰到两者对应上了,预览的时候还是提示错误, 查看了下网上其他大神的解决方法,是数据库字段类型有误,查看了下, ...

  5. 永久性for循环配合switch语句可以实现菜单功能

    永久性for循环配合switch语句可以实现菜单功能总结:加入想要无条件地跳转到某条语句执行,用goto语句: 加入想要对某种条件进行判断,为真或为假分别执行不同的语句,用if语句 加入想要检测的条件 ...

  6. ECSHOP常用函数

    lib_time.php gmtime() #获得当前格林威治时间的时间戳 /$0 server_timezone() #获得服务器的时区 /$0 local_mktime($hour = NULL ...

  7. POJ1054 枚举【STL__binary_search()_的应用】

    ①使用binary_search前要先保证有序 ②binary_search函数仅返回true或false ③binary_search(first element, laste lment + 1, ...

  8. sobel流水线操作Verilog程序

    sobel算子的verilog实现,采用了流水线操作 module sobel_computer ( clock , reset, OrigDataEn, //SobelAluEn, OrigData ...

  9. UNIX环境高级编程——进程管理和通信(总结)

    进程管理与通信 进程的管理 进程和程序的区别: 进程: 程序的一次执行过程   动态过程,进程的状态属性会发生变化 程序:存放在磁盘上的指令.数据的有序集合  是个文件,可直观看到 程序program ...

  10. XML(三)

     使用 XSLT 显示 XML -------------------------------------------------------------------------------- 通 ...