Iframe in MVC view to download asp.net web form

I have a controller called ProductController, and I use the index method to load the index view using a web form inside WebForm1.aspx, the index view is configured and working correctly. Now I want to add an iframe in the index view to display the contents of WebForm1.aspx. Both views are in the same Views / Products folder in the MVC project. I have done the following:

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

    </iframe>

my Views / web.config is installed as follows:

and WebForm inheritance is as follows:

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

However, the iframe displays an error message: "HTTP 404 - the resource you are looking for (or its dependencies) may have been deleted, its name changed or temporarily unavailable."

I also tried adding the following line to my global.asax file:

RouteTable.Routes.RouteExistingFiles = true;

but failed

The only way I get iFrame: but empty is to use the full physical path as follows:

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

    </iframe>

can someone explain why it is not working? And how to make it work? Thank.

+5
source share
3 answers

You should put your .aspx file (web form) from the views folder, because usually any call from the browser is blocked by the BlockViewHandler block (which you can see in the web.config file in the views folder).

In any other folder that you create, it should work without a controller. For example, if you put it in "/webforms/webform1.aspx", this path will be used to use the 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
    }
}

Index.html, aspx 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:

<%@ 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>
+13

Webform.aspx.

<iframe src="/FolderPath/WebForm1.aspx" width="1000" height="400">

    </iframe>

, MVC "ProductController" "Index"

Webform1.aspx , src src="/ProductsController/Index/WebForm1.aspx"

+1

webform MVC :

<iframe src="~/webform.aspx"...></iframe> 

.

, - MVC, webform open target = "_ parent"

0

All Articles