2011-06-19 69 views
0

我如何追加根據ID引用一個HTML元素的URL這樣追加 '#DIV ID' 使用的HtmlHelper

mysite.com/articles/1/my-first-article 

與DIV ID #commentList

mysite.com/articles/1/my-first-article#commentList 


<%: Html.ActionLink("text", "action", new {/* ??? HOW TO SET IT HERE ??? */})%> 

回答

2

元素嘗試使用proper overload(需要片段的那個),它將允許您生成包含片段部分的所需url:

<%= Html.ActionLink(
    "some text",  // linkText 
    "articles",  // actionName 
    null,   // controllerName 
    null,   // protocol 
    null,   // hostName 
    "commentList", // fragment <-- that's what you need 
    new { id = 1 }, // routeValues 
    null    // htmlAttributes 
) %>