前面3个参数,知道怎么回事,就是 超链接文字、视图、控制器,后边一大堆就很模糊了,请解释下,谢谢
- C# code
@Html.ActionLink("首页", "Index", "Home", null, (ctrl is HomeController) ? new { @class = "actived" } : null)@Html.ActionLink("视频", "Index", "Video", new { id = "pubdate" }, (ctrl is VideoController && (!new[] { "HotVideos", "Search", "Upload" }.Contains(action))) ? new { @class = "actived" } : null)@Html.RouteLink("专辑", "Paging", new { action = "Index", controller = "Album", id = "0" }, (ctrl is AlbumController) ? new { @class = "actived" } : null)@Html.ActionLink("排行", "HotVideos", "Video", new { id = "" }, (ctrl is VideoController && action == "HotVideos") ? new { @class = "actived" } : null)@Html.ActionLink("搜索", "Search", "Video", null, (ctrl is VideoController && action == "Search") ? new { @class = "actived" } : null)@Html.ActionLink("管理", "Index", "Admin", null, (ctrl is AccountController || ctrl is AdminController) ? new { @class = "actived" } : null)
------解决方案--------------------------------------------------------
? : 是三元运算,表示如果表达式成立,取:前面的,否则取后面的值
new { @class = "actived" } 这个是匿名类型对象初始化器语法。
------解决方案--------------------------------------------------------
is运算符判断一个对象是否属于这个类型或者这个类型的派生类型
------解决方案--------------------------------------------------------
漏了一个
@符号,第一个是Razor的标记
@class的不要搞混了,那个是用来转义标识符的,因为class在C#中是关键字,为了让一个属性也叫class,就需要加一个@
------解决方案--------------------------------------------------------
Contains是一个linq方法,表示 action 中不包含上述3个词组中的任何一个