Html.ActionLink

一 Html.ActionLink( " linkText " , " actionName " )

该重载的第一个参数是该链接要显示的文字,第二个参数是对应的控制器的方法,默认控制器为当前页面的控制器,如果当前页面的控制器为Products,则 Html.ActionLink(
" detail " , " Detail " ) 则会生成  < a href = " /Products/Detail " > all </ a >

二 Html.ActionLink(
" linkText " , " actionName " , " controlName " )

该重载比第一个重载多了一个参数,他指定了控制器的名称,如Html.ActionLink(
" detail " , " Detail " , " Products " )则会生成 < a href = " Products/Detail " > all </ a >

三 Html.ActionLik(
" linkText " , " actionName " ,routeValues)

routeValue可以向action传递参数,如Html.ActionLink(
" detail " , " Detail " , new  { id = 1 })会生成  < a href = " Products/Detail/1 " > detail </ a > , 此处假设当前的控制器是Products.

四 Html.ActionLink(
" linkText " , " actionName " ,routeValues,htmlAttributes)

htmlAttribute可以设置
< a > 标签的属性,如 Html.ActionLink( " detail " , " Detail " , new {id = 1 }, new { target = " _blank " })会生成  < a href = " Products/Detail/1 "  target = " _blank " > detail </ a > ,需要主要的是如果写成  new { target = " _blank " , class = " className " }则会报错,因为class是关键字,此处应该写成 @class = " className "

五 Html.ActionLink(
" linkText " , " actionName " , " controlName " ,routeValues,htmlAttributes)

该重载包含了上面提到的所有参数类型

六 Html.ActionLink(
" linkText " , " actionName " , " controlName " , " protocol " , " hostName " , " fragment " ,routeValues,htmlAttributes)

该重载使用比较少,他可以指定访问的协议,域名还有锚点,如 Html.ActionLink(
" liuwu " , " Detail " , " Products " , " http " , " www.liuwu.me " , " name " , null , null ) 可以生成  < a href = " http://www.liuwu.me/Products/Detail#name " > liuwu </ a >

你可能感兴趣的:(action)