最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - render partial view inside an iframe within asp.net mvc application - Stack Overflow

programmeradmin3浏览0评论

I have a asp mvc application in which I have a partial view named _GeoApi.cshtml.

I need to render it inside an iframe.

<iframe src='@{Html.RenderPartial("_GeoApi");}' id='fram' ></iframe> 

I get a generated html code :

<iframe<script src="/Scripts/External js/jquery-1.8.2.js">
<script src=";amp;libraries=places&amp;callback=initAutoplete" async="" defer=""></script>

//content removed for brivety

 src='' id='fram' /&gt; 

                                </iframe<script>

So I need to know

  1. What are the reasons of this error?
  2. How can I fix my code?

I have a asp mvc application in which I have a partial view named _GeoApi.cshtml.

I need to render it inside an iframe.

<iframe src='@{Html.RenderPartial("_GeoApi");}' id='fram' ></iframe> 

I get a generated html code :

<iframe<script src="/Scripts/External js/jquery-1.8.2.js">
<script src="https://maps.googleapis./maps/api/js?key=AIzaSyBCVSBoBAUjAfb-Pfx_qq0ZKUHCitbzsl4&amp;libraries=places&amp;callback=initAutoplete" async="" defer=""></script>

//content removed for brivety

 src='' id='fram' /&gt; 

                                </iframe<script>

So I need to know

  1. What are the reasons of this error?
  2. How can I fix my code?
Share Improve this question asked Mar 23, 2016 at 21:46 Lamloumi AfifLamloumi Afif 9,09127 gold badges106 silver badges193 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

Error is caused because you have a <script> tag in your <iframe> tag.

The solution is to simply provide a URL as the src to a URL where you would render the partial instead of trying to put the contents in the iframe tag.

<iframe src='/api/geoApi' id='fram' ></iframe> 

Then create an ApiController that has a GeoApi action method which renders the "_GeoApi" partial view.

发布评论

评论列表(0)

  1. 暂无评论