首页 > 其他 > 详细

辅助方法

时间:2015-06-26 13:26:21      阅读:154      评论:0      收藏:0      [点我收藏+]

1:Html.Actionlink与Html.RouteLink

ActionLink:辅助方法在后台使用路由API来生成URL,

@Html.ActionLink("LInk Text","AnotherAction")==><a href="/home/AnotherAction"></a>

重载版本:

@Html.ActionLink("LInk Text","方法名","Action",new {id=10086},null)

 

RouteLink:和ActionLink辅助方法遵循相同的模式,但是RouteLink只可以接收路由名称

2:Url辅助方法,Action/Content/RouteUrl

@Url.Action("Browse","Store",new {id=10086},null)==>/Store/Browse?id=10086

 RouteUrl:只可以接收路由名称

 Content:可以把应用程序的相对路径转化为绝对路径

3:Html.Partial和Html.RenderPartial,部分视图的渲染

@Html.Partial("partialViewName")

@{Html.RenderPartial("partialViewName")}

 从代码上可以看出,Partial比RenderPartial更加的方便,但partial返回的是字符串,RenderPartial是直接写入响应流,性能更加好

4:Html.Action和Html.RenderAction,同样的部分视图渲染,2者区别也一样,用法:

控制器-视图:

public class MyController:Controller
{
   public ActionResult Index()
  {
      return View();
  }
  
  [ChildActionOnly]
  public ActionResult Menu()
 {
   var menu=get..();
   return PartialView(menu); 
 }

}


@model Menu
<ul>
@foreach(var item in Model.MenuItem)
{
   <li>@item.Text</li>
}
</ul>


<html>
<head> <title>test<title></head>
<body>
@Html.Action("Menu");
</body>
</html>

 

辅助方法

原文:http://www.cnblogs.com/jameswenhe/p/4602004.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!