简体   繁体   English

在ASP.NET MVC应用程序内的iframe中呈现部分视图

[英]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&amp;libraries=places&amp;callback=initAutocomplete" 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? 如何修复我的代码?

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.

相关问题 在ASP.NET MVC中使用jQuery渲染局部视图 - Render Partial View Using jQuery in ASP.NET MVC Asp.Net Mvc渲染局部视图 - Asp.Net Mvc Render Partial View With Knockout asp.net mvc使用Java Script渲染部分视图 - asp.net mvc Render a Partial View with Java Script 如何在.NET MVC应用程序的href标记内呈现部分视图 - How to render partial view inside href tag in .NET MVC application 从ASP.NET MVC Partial View中调用JavaScript - Call JavaScript from within an ASP.NET MVC Partial View 在ASP.NET MVC的部分视图中执行Javascript - Execute Javascript inside a partial view in ASP.NET MVC 将数据从 JavaScript 代码传递到基于 ASP.NET Core 3.1 MVC 的应用程序中的 Razor 分部视图 - Passing data from JavaScript code to the a Razor partial view within ASP.NET Core 3.1 MVC based application 一个页面上的Asp.net MVC多个(相同)局部视图<script> tags inside Partial View - Asp.net MVC Multiple (of the same) Partial Views on a page with <script> tags inside Partial View 使用ASP.NET MVC和jQuery呈现部分视图/提交表单,而无需刷新页面 - Using ASP.NET MVC and jQuery to render partial view/submit a form without page refresh 如何在ASP.NET应用程序中的accordian div中加载局部视图? - How do you load a partial view within an accordian div in an ASP.NET application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM