Facebook像按钮iframe与动态网址打印在asp.net剃刀模板中

时间:2011-07-25 08:41:10

标签: asp.net razor umbraco facebook-like

我在umbraco cms中有一个asp.net网站,在那里我可以使用razor模板来创建一些宏。 我想在页面中集成一个类似facebook的按钮, 这只适用于我在razor宏中粘贴iframe并将宏包含在我的母版页上的时候。

但是,如果我想要包含一些参数, 然后我从代码片段中取出iframe网址,将另一个参数粘贴到该网址中 它停止工作。

但是,渲染后iframe网址100%完全相同。

任何人都知道如何确保Facebook iframe参数可以更改的正确网站网址? (取决于我在umbraco cms中绑定的主机名)

这是我的剃刀代码不起作用:

@{
  var currentLangPath = "www.newurl.com"; 
  var iframeSource = "http://www.facebook.com/plugins/like.php?app_id=207125959336150&href=" + currentLangPath + "&send=false&layout=button_count&width=110&show_faces=false&action=like&colorscheme=dark&font=arial&height=21";      
  }

<a href="#visitFanpage"><img src="/images/facebook_logo.jpg" alt="Solex Facebook" /></a>
<p>Become part of the community, and feel free to share your experience.</p>
<div class="social">
  <iframe src="@iframeSource" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:110px; height:25px;" allowTransparency="true"></iframe>
</div>

以下是可行的Razor文件的内容:

<a href="#visitFanpage"><img src="/images/facebook_logo.jpg" alt="Solex Facebook" /></a>
<p>Become part of the community, and feel free to share your experience.</p>
<div class="social">
  <iframe src="http://www.facebook.com/plugins/like.php?app_id=207125959336150&amp;href=www.newurl.com&amp;send=false&amp;layout=button_count&amp;width=110&amp;show_faces=false&amp;action=like&amp;colorscheme=dark&amp;font=arial&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:110px; height:25px;" allowTransparency="true"></iframe>
</div>

请注意,这两个Razor文件都具有完全相同的输出,因此我发现动态URL不起作用非常奇怪。

1 个答案:

答案 0 :(得分:2)

输出实际上并不相同,iframeSource变量得到HTML编码,因此是“&amp; amp;”变成:

&amp;amp;

你可以做两件事:

  1. 删除“amp;”在每个“&amp;”之后在iframeSource
  2. 使用@ Html.Raw(iframeSource)
  3. 代替@iframeSource