Có một tình trạng quá tải của các helper ActionLink cho phép bạn chỉ định các đoạn:
@Html.ActionLink(
"Link Text", // linkText
"Action", // actionName
"Controller", // controllerName
null, // protocol
null, // hostName
"fragment", // fragment
new { id = "123" }, // routeValues
null // htmlAttributes
)
sẽ tạo ra (giả sử các tuyến đường mặc định):
<a href="/Controller/Action/123#fragment">Link Text</a>
UPDATE:
và nếu bạn muốn thực hiện điều này trong hành động điều khiển thực hiện chuyển hướng, bạn có thể sử dụng các phương pháp GenerateUrl:
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);
}
Nguồn
2011-10-26 15:22:11
http://stackoverflow.com/questions/10690466/redirect-to-a-hash-from-the-controller-using-redirecttoaction – hidden