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. 二分法查找 --JS 实现

    var indexOfSorted = function f(arr,n){ //assume : arr has been sorted var low = 0; var high = arr.le ...

  2. iOS 日历控件

    近期需要写一个交互有点DT的日历控件,具体交互细节这里略过不表. 不过再怎么复杂的控件,也是由基础的零配件组装起来的,这里最基本的就是日历控件. 先上图: 从图中可以看出日历控件就是由一个个小方块组成 ...

  3. BZOJ 1103: [POI2007]大都市meg( 树链剖分 )

    早上数学考挂了...欲哭无泪啊下午去写半个小时政治然后就又可以来刷题了.. 树链剖分 , 为什么跑得这么慢... ------------------------------------------- ...

  4. Android:Service的注意点以及一些知识点

    1.自己练习service的start()方法开启一个service服务的时候,不管怎么开启按钮,就是开启不了service服务,控制台也没有报错信息, app不闪退,代码就那么几行.找了好久找不出来 ...

  5. pkg_zhgl

    CREATE OR REPLACE PACKAGE BODY PKG_ZHGL AS --账户管理包 code szn 20110829 --账户管理服务包 --定义本包中需要引用到的常量 --定义说 ...

  6. 如何在.Net中使用Redis

    Redis是一个key-value存储系统.和Memcached类似,但是解决了断电后数据完全丢失的情况,而且她支持更多无化的value类型,除了和string外,还支持lists(链表).sets( ...

  7. SVProgressHUD的使用

    GitHub:https://github.com/samvermette/SVProgressHUD SVProgressHUD和MBProgressHUD效果差点儿相同,只是不须要使用协议,同一时 ...

  8. HDU 4814 Golden Radio Base 小模拟

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 题意:黄金比例切割点是,如今要求把一个10进制的的数转化成一个phi进制的数,而且不能出现'11'的 ...

  9. Eclipse中JBOSS5.1无法启动的问题解决办法

    今天在Eclipse中启动JBoss 5.1时遇到这样的一个错误: …… ERROR [AbstractKernelController] Error installing to Instantiat ...

  10. MIT 三课程

    mit三课程: Introduction to Computer Science and Programming artificial intelligence introduction to alg ...