Asp.net mvc 在ASP.NETMVC中,如何生成facebook链接?
在ASP.NETMVC中,如何生成以下链接Asp.net mvc 在ASP.NETMVC中,如何生成facebook链接?,asp.net-mvc,hyperlink,Asp.net Mvc,Hyperlink,在ASP.NETMVC中,如何生成以下链接 <a class="facebook" rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u=HTTP://myreallycoolsite.com/somegroup/somechildgroup/some_title/">some_title</a> 并且它需要用作外部链接的参数。正常创建链接并将@Request.Url.ToSt
<a class="facebook" rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u=HTTP://myreallycoolsite.com/somegroup/somechildgroup/some_title/">some_title</a>
并且它需要用作外部链接的参数。正常创建链接并将@Request.Url.ToString放入其中。如果您需要动态地将some_title文本放入其中,那么您将需要执行一些不同的操作之一。如果它是路线的一部分,那么你可以从RouteData中提取它。如果它是页面的标题,您可能会使用ViewBag.title。如果它是完全任意的,您可能只需要使用正则表达式
<a class="facebook" rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u=@Request.Url.ToString()">some_title</a>
正常创建链接并将@Request.Url.ToString放入其中。如果您需要动态地将some_title文本放入其中,那么您将需要执行一些不同的操作之一。如果它是路线的一部分,那么你可以从RouteData中提取它。如果它是页面的标题,您可能会使用ViewBag.title。如果它是完全任意的,您可能只需要使用正则表达式
<a class="facebook" rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u=@Request.Url.ToString()">some_title</a>
这是剃须刀:
@{
// you can inline this instead
var Param = Url.Encode(Url.Action("action", "controller", new{ /*params*/ });
^^^^^
// or for the current page's URL (hat tip @Dismissile)
Param = Url.Encode(Request.Url.ToString());
}
<a class="facebook"
rel="nofollow"
target="_blank"
href="http://www.facebook.com/sharer.php?u=@Param">some_title</a>
^^^^^^
如果您没有使用Razor,它看起来像这样,或者至少接近这样:
<%
// you can inline this instead
var Param = Url.Encode(Url.Action("action", "controller", new{ /*params*/ });
^^^^^
// or for the current page's URL (hat tip @Dismissile)
Param = Url.Encode(Request.Url.ToString());
%>
<a class="facebook"
rel="nofollow"
target="_blank"
href="http://www.facebook.com/sharer.php?u=<%=Param%>">some_title</a>
^^^^^^
这是剃须刀:
@{
// you can inline this instead
var Param = Url.Encode(Url.Action("action", "controller", new{ /*params*/ });
^^^^^
// or for the current page's URL (hat tip @Dismissile)
Param = Url.Encode(Request.Url.ToString());
}
<a class="facebook"
rel="nofollow"
target="_blank"
href="http://www.facebook.com/sharer.php?u=@Param">some_title</a>
^^^^^^
如果您没有使用Razor,它看起来像这样,或者至少接近这样:
<%
// you can inline this instead
var Param = Url.Encode(Url.Action("action", "controller", new{ /*params*/ });
^^^^^
// or for the current page's URL (hat tip @Dismissile)
Param = Url.Encode(Request.Url.ToString());
%>
<a class="facebook"
rel="nofollow"
target="_blank"
href="http://www.facebook.com/sharer.php?u=<%=Param%>">some_title</a>
^^^^^^
试试这个
<a href="#"
onclick="
window.open(
'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
'facebook-share-dialog',
'width=626,height=436');
return false;">
Share on Facebook
</a>
试试这个
<a href="#"
onclick="
window.open(
'https://www.facebook.com/sharer/sharer.php?u='+encodeURIComponent(location.href),
'facebook-share-dialog',
'width=626,height=436');
return false;">
Share on Facebook
</a>
您是否可以使用Param=Request.Url.AbsoluteUri避免编码?您是否可以使用Param=Request.Url.AbsoluteUri避免编码?