问题
is there any helper in asp.net MVC3
<a href="www.google.com">Go to Google </a>
?
Not for an action but to a static link
回答1:
I don't believe there is, but I'm not sure why you would want one. You'd actually end up with more code:
<a href="http://www.google.com/">Go to Google</a>
<%: Html.Link("http://www.google.com/", "Go to Google") %>
@Html.Link("http://www.google.com/", "Go to Google")
Update: If you want to create a Link()
helper like that above, you would use an extension method:
public static class LinkExtensions
{
public static MvcHtmlString Link(this HtmlHelper helper, string href, string text)
{
var builder = new TagBuilder("a");
builder.MergeAttribute("href", href);
builder.SetInnerText(text);
return MvcHtmlString.Create(builder.ToString(TagRenderMode.Normal));
}
}
来源:https://stackoverflow.com/questions/5400571/helper-for-tag-html-a