2016-03-23 39 views
-1

我有一個asp.net mvc應用程序,其中我有一個名爲_GeoApi.cshtml的局部視圖。在asp.net mvc應用程序內的iframe中渲染局部視圖

我需要在iframe內呈現它。

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

我得到一個生成的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> 

所以,我需要知道

  1. 什麼是這個錯誤的原因是什麼?
  2. 我該如何修復我的代碼?

回答

1

錯誤是由於您的標記中有一個<script>標記而引起的。

解決方案是簡單地提供一個URL作爲src到一個URL,在那裏你會呈現部分內容,而不是試圖把內容放在iframe標籤中。

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

然後創建一個ApiController,它具有呈現「_GeoApi」局部視圖的GeoApi操作方法。