IFRAME在MVC视图加载asp.net web表单 [英] iframe in an MVC view to load asp.net web form

查看:290
本文介绍了IFRAME在MVC视图加载asp.net web表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个叫ProductsController的控制器和I使用索引方法加载一个网页表单中调用WebForm1.aspx的,该索引视图已建立并正常工作的索引视图。现在我想在索引视图中添加一个iframe来显示WebForm1.aspx的内容。这两种观点都在同一个文件夹视图/产品在MVC项目。我做了以下内容:

I have a controller called ProductsController and I use the index method to load the index view with a web form inside called WebForm1.aspx, The index view has been set up and is working properly. Now I want to add an iframe in the index view to display the content of WebForm1.aspx. Both views are in the same folder Views/Products in the MVC project. I did the following:

    <iframe src="/ProductsController/Index?WebForm1.aspx" width="1000" height="400">

    </iframe>

我的看法/ web.config中设置为下一个:

my Views/web.config is set as next:


  
  

和WebForm的继承是下一:

and the WebForm inheritance is as next:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

然而,IFRAME显示错误信息:HTTP 404 - 你正在寻找(或它的一个依赖)可能已被删除的资源,更名或暂时不可用。

Yet the iframe display an error message: "HTTP 404 - The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable."

我也尝试添加到我的Global.asax文件的下一行:

I tried also to add to my global.asax file the next line:

RouteTable.Routes.RouteExistingFiles = true;

但也失败了,

独特的方式,我得到的iFrame显示的,但空是使用完整物理路径为下一:

The unique way I get iFrame displayed but empty is to use the full physical path as next:

    <iframe src="C\:Folder1\Folder2\ ...\Views\Products\WebForm1.aspx" width="1000" height="400">

    </iframe>

有人可以解释为什么它不工作?而如何使其工作?谢谢你。

can someone explain why it does not work? And how to make it work? Thank you.

推荐答案

您应该把您的.aspx文件(表单)从意见的文件夹,因为通常从浏览器的调用是由BlockViewHandler(块你可以在views文件夹的web.config文件见)。

You should put your .aspx file (webform) out of the views folder, because normally any call from the browser is block by the "BlockViewHandler" (which you can see in the web.config file of the views folder).

在您创建的任何其他文件夹,它应该工作,没有一个控制器。
例如,如果你把它放在/webforms/webform1.aspx这条道路是利用联合国的iframe的人。

In any other folder that you create, it should work without a controller. For example if you put it in "/webforms/webform1.aspx" that path is the one to use un the iframe.

更新下面是在问题的新的信息的例子,希望它可以帮助:

UPDATE Here is an example with the new information in the question, hope it can help:

控制器:

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
    }
}

产品的Index.html的内容,通过iframe调用aspx文件:

The content of Products Index.html, calling the aspx file via an iframe:

@{
    ViewBag.Title = "Index title";
}

<h2>Index</h2>

Calling aspx file from iframe:

<iframe src="@Url.Action("ActionThatRetrieveAndAspx","Products")" width="1000" height="400"></iframe>

产品WebForm1.aspx的的内容:

The content of Products 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>

这篇关于IFRAME在MVC视图加载asp.net web表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆