Sam*_*i-L 6 asp.net iframe html5 asp.net-mvc-4
我有一个名为ProductsController的控制器,我使用索引方法在一个名为WebForm1.aspx的Web表单中加载索引视图,索引视图已经设置并且工作正常.现在我想在索引视图中添加一个iframe来显示WebForm1.aspx的内容.两个视图都位于MVC项目中的Views/Products文件夹中.我做了以下事情:
<iframe src="/ProductsController/Index?WebForm1.aspx" width="1000" height="400">
</iframe>
Run Code Online (Sandbox Code Playgroud)
我的Views/web.config设置为next:
并且WebForm继承如下:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
Run Code Online (Sandbox Code Playgroud)
然而,iframe显示错误消息:"HTTP 404 - 您正在寻找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用."
我还尝试将下一行添加到我的global.asax文件中:
RouteTable.Routes.RouteExistingFiles = true;
Run Code Online (Sandbox Code Playgroud)
但也失败了,
我得到iFrame 但显示为空的独特方式是使用完整的物理路径作为下一个:
<iframe src="C\:Folder1\Folder2\ ...\Views\Products\WebForm1.aspx" width="1000" height="400">
</iframe>
Run Code Online (Sandbox Code Playgroud)
谁能解释为什么它不起作用?以及如何使它工作?谢谢.
jhe*_*era 13
您应该将.aspx文件(webform)放在views文件夹之外,因为通常来自浏览器的任何调用都会被"BlockViewHandler"阻塞(您可以在views文件夹的web.config文件中看到).
在您创建的任何其他文件夹中,它应该在没有控制器的情况下工作.例如,如果您将其放在"/webforms/webform1.aspx"中,则该路径是使用iframe的路径.
更新以下是问题中新信息的示例,希望它可以提供帮助:
控制器:
public class ProductsController : Controller
{
public ActionResult Index()
{
return View(); //Razor file in Views/Products/Index.cshtml
}
public ActionResult ActionThatRetrieveAndAspx()
{
return View("WebForm1"); //Aspx file Views/Products/WebForm1.aspx
}
}
Run Code Online (Sandbox Code Playgroud)
产品Index.html的内容,通过iframe调用aspx文件:
@{
ViewBag.Title = "Index title";
}
<h2>Index</h2>
Calling aspx file from iframe:
<iframe src="@Url.Action("ActionThatRetrieveAndAspx","Products")" width="1000" height="400"></iframe>
Run Code Online (Sandbox Code Playgroud)
产品WebForm1.aspx的内容:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Title</title>
</head>
<body style="background-color: #999999; padding: 10px;">
This is ActionThatRetrieveAndAspx WebForm1.aspx
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
您可以指向 Webform.aspx 文件的实际位置。
<iframe src="/FolderPath/WebForm1.aspx" width="1000" height="400">
</iframe>
Run Code Online (Sandbox Code Playgroud)
您的代码假设 MVC 运行时将查看一个名为“ProductsController”的文件夹和一个名为“Index”的子文件夹
如果您的 Webform1.aspx 文件确实位于该目录结构中,请将 src 属性更改为src="/ProductsController/Index/WebForm1.aspx"
| 归档时间: |
|
| 查看次数: |
52543 次 |
| 最近记录: |