我怎么能一个锚标记添加到我的网址是什么? [英] How can I add an anchor tag to my URL?
本文介绍了我怎么能一个锚标记添加到我的网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MVC 3.net我想一个锚添加到末尾的URL。
MVC 3.net I want to add an anchor to the end a url.
我想包括锚查询字符串,但散'#'到23%变更或类似的东西在URL中。
I tried to include an anchor query string but the hash '#' changes to %23 or something like that in the url.
有没有解决这个的一种工作方式?
Is there a way of working around this?
推荐答案
有是的ActionLink 帮手允许您指定片段:
There is an overload of the ActionLink helper that allows you to specify the fragment:
@Html.ActionLink(
"Link Text", // linkText
"Action", // actionName
"Controller", // controllerName
null, // protocol
null, // hostName
"fragment", // fragment
new { id = "123" }, // routeValues
null // htmlAttributes
)
将产生(假设默认路由):
will produce (assuming default routes):
<a href="/Controller/Action/123#fragment">Link Text</a>
更新:
如果你想要一个控制器动作中做到这一点执行重定向,你可以使用 GenerateUrl 一>方法:
and if you wanted to do this within a controller action performing a redirect you could use the GenerateUrl method:
public ActionResult Index()
{
var url = UrlHelper.GenerateUrl(
null,
"Action",
"Controller",
null,
null,
"fragment",
new RouteValueDictionary(new { id = "123" }),
Url.RouteCollection,
Url.RequestContext,
false
);
return Redirect(url);
}
这篇关于我怎么能一个锚标记添加到我的网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文