开发者

Quick question. Html.ActionLink and creating Internal Links ( #home, #about, etc. )

开发者 https://www.devze.com 2023-01-03 22:21 出处:网络
quick question... How can I best create internal links? This is the markup I want to achieve: <h3>Title</h3>

quick question...

How can I best create internal links? This is the markup I want to achieve:

<h3>Title</h3>
<ul>
  <li><a href="#prod1">Product 1</li>
  <li><a href="#prod2">Product 2</li>
  <li><a href="#prod3">Product 3</li>
  ...
  <li><a href="#prod100">Product 100</li>
</ul>

<div id="prod1">
  <!-- content here -->
</div>

Using MVC 2 I'm using, what's the best Html Helper to use?

<h3><%= Html.Encode(Model.Title) %>
<ul>

<% foreach ( var ite开发者_如何学编程m in Model.Categories ) {%>
    <li><%= Html.RouteLink( item.Description, ???? ) %></li>
<%} %>

</ul>

What's the best way to get a url to an internal link? String.Format a link from scratch? There's gotta be a better way.


public static TagBuilder LocalAnchor(this HtmlHelper helper, string anchor, string text)
{
    var tag = new TagBuilder("a");
    tag.MergeAttribute("href", "#" + anchor);
    tag.SetInnerText(text);
    return tag;
}


">

The routing features weren't meant for internal links; you have to generate them yourself.

0

精彩评论

暂无评论...
验证码 换一张
取 消