[英]render partial view inside an iframe within asp.net mvc application
I have a asp.net mvc application in which I have a partial view named _GeoApi.cshtml
. 我有一个asp.net mvc应用程序,其中有一个名为
_GeoApi.cshtml
的局部视图。
I need to render it inside an iframe . 我需要在iframe中渲染它。
<iframe src='@{Html.RenderPartial("_GeoApi");}' id='fram' ></iframe>
I get a generated html code : 我得到一个生成的html代码:
<iframe<script src="/Scripts/External js/jquery-1.8.2.js">
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBCVSBoBAUjAfb-Pfx_qq0ZKUHCitbzsl4&libraries=places&callback=initAutocomplete" async="" defer=""></script>
//content removed for brivety
src='' id='fram' />
</iframe<script>
So I need to know 所以我要知道
Error is caused because you have a <script>
tag in your <iframe>
tag. 由于您的
<iframe>
标记中包含<script>
标记而导致错误。
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. 解决方案是简单地将URL作为src提供给您将在其中呈现部分内容的URL,而不是尝试将内容放入iframe标记中。
<iframe src='/api/geoApi' id='fram' ></iframe>
Then create an ApiController that has a GeoApi action method which renders the "_GeoApi" partial view. 然后创建一个具有GeoApi动作方法的ApiController,该方法呈现“ _GeoApi”局部视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.