1. @Html.Raw() 方法输出带有html标签的字符串:

<div style="margin:10px 0px 0px;border:1px;border-color:red;border-style:dotted;">
<h4>Title:Html.Raw</h4>
Html.Raw:@Html.Raw("<div style=\'background-color:red \'>HelloWorld!</div>")
</div>

自我分析:直接输出HTML内容!

2. @html.ActionLink生成一个<a href=".."></a>标记:

<div style="margin:10px 0px 0px;border:1px;border-color:red;border-style:dotted;">
<h4>Title:Html.ActionLink</h4>
Example Of Usage: Html.ActionLink("linkText","ActionName","ControlName",new { id = "911"},new{ target="_blank"})
<br />
@Html.ActionLink("Click Me!", "GetView", "Test", new { id = " 11" }, new { target = "_blank" })
</div>

自我分析:直接输出一个<a></a>标签,即返回一个/Controller/Action/形式的Link!

3. @Url.Action

<div style="margin:10px 0px 0px;border:1px;border-color:purple;border-style:dotted;">
<h4>Title:Url.Action</h4>
Example Of Usage:Url.Action("ActionName","ControlName",new { id = "911" })
<br />
@Url.Action("GetView", "Test", new { id = "12" })
</div>

自我分析:返回一个/Controller/Action形式的url,这应该是对Url.Action最形象的说明了吧!

4. @Html.Action

View:

<div style="margin:10px 0px 0px;border:1px;border-color:blue;border-style:dotted;">
<h4>Title:Html.Action</h4>
Example Of Usage: Html.Action("ActionName", "ControlName") PS.Invoke the Partial View
<br />
@Html.Action("GetMyPartialView", "Test")
</div>

Action:

public ActionResult GetMyPartialView()
{
EmployeeBusinessLayer bl = new EmployeeBusinessLayer();
List<Employee> empList = bl.GetEmployeeList();
EmployeeListViewModels empVMEmp = new EmployeeListViewModels(); for (int i = ; i < empList.Count; i++)
{
EmployeeViewModels newEmp = new EmployeeViewModels();
newEmp.EmployeeName = empList[i].FirstName + " " + empList[i].LastName; if (empList[i].Salary > )
{
newEmp.SalaryColor = "Red";
}
else
{
newEmp.SalaryColor = "Yellow";
}
newEmp.Salary = empList[i].Salary.ToString();
empVMEmp.employeeList.Add(newEmp);
}
empVMEmp.UserName = "admin";
return View("MyPartialView", empVMEmp);
}

自我分析:加载公共部分的代码如当前登录用户在各个页面的信息显示,也可以理解为返回一个由/Controller/Action/构造的HTML文本内容并进行呈现。

5. @Html.RenderAction

View:

<div style="margin:10px 0px 0px;border:1px;border-color:orange;border-style:dotted;">
<h4>Title:Html.RenderAction</h4>
Usage Of Example:@{Html.RenderAction("PartialView Name","ControlName");}
<br />
@{Html.RenderAction("GetMyPartialView", "Test");}
</div>

Action:

public ActionResult GetMyPartialView()
{
EmployeeBusinessLayer bl = new EmployeeBusinessLayer();
List<Employee> empList = bl.GetEmployeeList();
EmployeeListViewModels empVMEmp = new EmployeeListViewModels(); for (int i = ; i < empList.Count; i++)
{
EmployeeViewModels newEmp = new EmployeeViewModels();
newEmp.EmployeeName = empList[i].FirstName + " " + empList[i].LastName; if (empList[i].Salary > )
{
newEmp.SalaryColor = "Red";
}
else
{
newEmp.SalaryColor = "Yellow";
}
newEmp.Salary = empList[i].Salary.ToString();
empVMEmp.employeeList.Add(newEmp);
}
empVMEmp.UserName = "admin";
return View("MyPartialView", empVMEmp);
}

6.总结:@Html.ActionLink和@Url.Action都是为了实现页面跳转而用于生成链接用的。而Html.Partial/Html.RenderPartial/Html.Action/Html.RenderAction则是用于页面中嵌入部分视图/用户控件/动态内容,具体区别参见下表:

ASP.NET MVC Html.Partial/Html.RenderPartial/Html.Action/Html.RenderAction区别的更多相关文章

  1. Html.Partial,Html.RenderPartial Html.Action,Html.RenderAction区别

    @Html.Partial,@Html.RenderPartial      这两者的共同点都是在视图中去调用另外一个视图,区别是   Html.Partial 有返回值 ( MvcHtmlStrin ...

  2. MVC 部分视图:Partial() 、RenderPartial() 、 Action() 、RenderAction() 、 RenderPage() 区别

    在视图里有多种方法可以 加载部分视图,包括: Partial()  Action()  RenderPartial()  RenderAction()  RenderPage() 方法. 以下是这些方 ...

  3. asp.net mvc @Html.Partial @Html.Action @Html.RenderPartial @Html.RenderAction区别

    转载自 :  <asp.net mvc @Html.Partial @Html.Action @Html.RenderPartial @Html.RenderAction区别> 先复制过来 ...

  4. ASP.NET MVC中默认Model Binder绑定Action参数为List、Dictionary等集合的实例

    在实际的ASP.NET mvc项目开发中,有时会遇到一个参数是一个List.Dictionary等集合类型的情况,默认的情况ASP.NET MVC框架是怎么为我们绑定ASP.NET MVC的Actio ...

  5. [转]ASP.NET MVC 入门4、Controller与Action

    Controller是MVC中比较重要的一部分.几乎所有的业务逻辑都是在这里进行处理的,并且从Model中取出数据.在ASP.NET MVC Preview5中,将原来的Controller类一分为二 ...

  6. ASP.NET MVC 入门4、Controller与Action

    原帖地址:http://www.cnblogs.com/QLeelulu/archive/2008/10/04/1303672.html Controller是MVC中比較重要的一部分.差点儿全部的业 ...

  7. Html.PartialView(),html.Renderpartial,html.action.html.RenderAction 辅助方法

    Html.Partial(), 返回HTML字符串 .参数为部分视图 html.RenderPartial(),不返回返回HTML字符串 ,直接输出响应流.参数为部分视图 一般用于主视图中已经存在了这 ...

  8. asp.net MVC中获取当前URL/Controller/Action

    一.获取URL(ASP.NET通用): [1]获取完整url(协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [2]获取虚拟目录名+页面 ...

  9. 【ASP.NET MVC 学习笔记】- 13 Child Action

    本文参考:http://www.cnblogs.com/willick/p/3410855.html 1.Child action 和 Patial view 类似,也是在应用程序的不同地方可以重复利 ...

随机推荐

  1. 程序最多能new多少内存(2G内存里要放程序的5大区,HeapAlloc比new要快多了,而且超过2G的时候会告诉你)

    根据<Windows核心编程>得知:X86操作系统提供每个程序最多只有4G的虚拟内存,其中2G虚拟内存提供给系统用(具体用来干什么还待考察),还有2G的内存留给用户使用.那这2G内存能拿来 ...

  2. HTML其他基本格式说明

    1.<!DOCTYPE>说明页面中使用的HTML版本,只是信息声明 2.元信息元素<meta>,通过属性定义文件信息的名称.内容.文档的关键字.作者及描述等..content内 ...

  3. JMeter学习-004-WEB脚本入门实战

    此文为 JMeter 入门实战实例.我是 JMeter 初学菜鸟一个,因而此文适合 JMeter 初学者参阅.同时,因本人知识有限,若文中存在不足的地方,敬请大神不吝指正,非常感谢! 闲话少述,话归正 ...

  4. 纯代码TableView自适应高度(很老的使用方法)

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return  ...

  5. Python开发【第二章】:Python深浅拷贝剖析

    Python深浅拷贝剖析 Python中,对象的赋值,拷贝(深/浅拷贝)之间是有差异的,如果使用的时候不注意,就可能产生意外的结果. 下面本文就通过简单的例子介绍一下这些概念之间的差别. 一.对象赋值 ...

  6. struts2-通配符映射(基本没啥卵用)和动态调用

    通配符 使用*代表任意字符 一般在action的name中使用*,并可以使用多个 可以使用{通配符的序号}引用对应的通配符所代表的值,序号从1开始 {0}代表整个URI 匹配规则 首先完全匹配,没有完 ...

  7. 全网扫描扫描10000端口后的优化脚本&域名列表指定端口的批量测试

    方法一: #coding=utf-8 import urllib2 import threading from time import ctime,sleep print "Start-Ti ...

  8. paper 112:hellinger distance

    在概率论和统计理论中,Hellinger距离被用来度量两个概率分布的相似度.它是f散度的一种(f散度——度量两个概率分布相似度的指标).Hellinger距离被定义成Hellinger积分的形式,这种 ...

  9. IUS tcl cmd

    Incisive simulator中的command-line language基于TCL. Ncsim> command [-modifier] [-options] [arguments] ...

  10. python 清楚数组重复字符串元素

    l1 = ['bb','c','d','bb','c','a','a'] l2 = {}.fromkeys(l1).keys() print (l2)