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. easyUI loyout tabs自适应宽度

    index.html 页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http ...

  2. JS 获取 地址栏 参数

    法一:正则表达式 /** * 采用正则表达式获取地址栏参数: **/ var GetQueryString = function (name) { var reg = new RegExp(" ...

  3. [转]Android View.onMeasure方法的理解

    转自:http://blog.sina.com.cn/s/blog_61fbf8d10100zzoy.html Android View.onMeasure方法的理解 View在屏幕上显示出来要先经过 ...

  4. LeetCode Paint Fence

    原题链接在这里:https://leetcode.com/problems/paint-fence/ 题目: There is a fence with n posts, each post can ...

  5. DNS子域授权与转发配置

    正向区域SUB_ZONE_NAME IN NS NSSERVER_SUB_ZONE_NAME NSSERVER_SUB_ZONE_NAME IN A IP .com xingxing.com. xin ...

  6. Eclipse安装maven插件报错

    Eclipse安装maven插件,报错信息如下: Cannot complete the install because one or more required items could not be ...

  7. jq数组,得到遍历生成的id后面的id

    //商品选择完成跳转到提交订单页面 function orderDetails(){ var shopCarIds = [];//存放商品的数组 var objs = []; objs = $(&qu ...

  8. 简单Hosts使用说明

    1.查找hosts文件 首先,点击桌面的"我的电脑",或者是通过开始菜单进入到我的电脑. 之后,进入到"C:\Windows\System32\drivers\etc&q ...

  9. bzoj2729 [HNOI2012]排队

    组合数学,推一下式子,并不难推. java代码 import java.io.*; import java.math.BigInteger; import java.util.*; public cl ...

  10. 如何写出优雅的Python之设置class缺省值

    今天有个需求时需要为某个类设置缺省值 最开始的代码如下: Class myClass def __init__(self,datalen=None,times=None): if datalen == ...