如何在Controller操作中从URL读取锚点。
示例网址:www.site.com/some-action#anchor-what-i-want-read
public ActionResult SomeAction()
{
// Here i want read the anchor
}
原因: 我需要通过锚标记设置og:图像为Facebook。因为我的页面上有太多项目。所以自动脸书图像抓取不起作用。我使用锚点直接导航到页面上的产品。
最终解决方案:
我在链接www.site.com/some-action/ id 中添加了可选的URL参数,因此我可以通过此参数解析FB og:image,并使用JS pro导航到锚点通过该参数形式的URL。
答案 0 :(得分:0)
在我的项目中,所有这些操作都加载了$ .ajax()。像这样的东西:
var href = window.location.href;
href = href.substr(0, href.indexOf('#'));
href += (href.indexOf("?") == -1 ? "?" : "&") + "hashvalue=" + window.location.hash.substr(1);
$.ajax({
url: href,
success: function(response){
// write to content holder this response
}
});
说实话,我的所有行动都是http://my.site.com/#!controllername/actionname