MVC嵌入局部视图到一个文件撰写JS调用 [英] Embed MVC Partial View into a document.write JS call
问题描述
我创建将被嵌入到一个第三方网站的JavaScript文件。 JavaScript文件将呈现一些内容到第三方网站。这个想法是一样的谷歌AdSense - 网站所有者放在其网站JS文件,和一些广告出现在该位置
我打开替代方法,但我试图通过具有嵌入式JS文件根本就做到这一点:
的document.write('广告内容')
不过,我的广告内容嵌入在ASP.NET MVC3局部视图。我如何能逃脱从Html.Partial方法返回一个有效的JS字符串的内容?
我在寻找类似:
的document.write(@ Html.JavascriptEscapedPartial(/共享/ _AdContent))
<$p$p><$c$c>document.write('@Html.Raw(HttpUtility.JavaScriptStringEn$c$c(Html.Partial(\"~/Views/Shared/_AdContent\").ToHtmlString()))')
I am creating a Javascript file that will be embedded onto a 3rd party site. The Javascript file will render some content onto the third party site. The idea is the same as Google Adsense - web site owner places a JS file on their site, and some advertisements appear in that location.
I am open to alternative methods, but I am trying to accomplish this by having the embedded JS file simply do:
document.write('Advertisement content')
However, my advertisement content is embedded in ASP.NET MVC3 partial view. How can I escape the content returned from the Html.Partial method to a valid JS string?
I'm looking for something like:
document.write(@Html.JavascriptEscapedPartial("/Shared/_AdContent"))
document.write('@Html.Raw(HttpUtility.JavaScriptStringEncode(Html.Partial("~/Views/Shared/_AdContent").ToHtmlString()))')
这篇关于MVC嵌入局部视图到一个文件撰写JS调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!