如何在iframe src中使用Url.Action

时间:2013-07-16 11:25:36

标签: asp.net-mvc-4 iframe url-action

如何使用Url.Action iframe属性中的src方法。像

<iframe src = '<%=Url.Action("HelloWorld", "myController");%>' width = "100%" height="1000" frameBorder="0"></iframe>

但它不能正常工作。它说所要求的内容不可用。

请帮帮我

2 个答案:

答案 0 :(得分:10)

使用ASP.NET引擎

<iframe src = '<%: Url.Action("HelloWorld", "myController") %>' width = "100%" 
    height="1000" frameBorder="0"></iframe>

使用剃须刀引擎。

<iframe src = '@Url.Action("HelloWorld", "myController")' width = "100%" 
    height="1000" frameBorder="0"></iframe>

答案 1 :(得分:0)

Same here found error in getting what type of Controller should be? so this is the best solution if you are using IFrame for PDF Viewer and I hope this code will be useful.


<iframe src="@Url.Action("GetPDF")" id="sign" width="800" height="800"></iframe>

  public FileStreamResult GetPDF()
        {
            var path = "E:\\FirstTask\\FirstTask\\FolderToSave\\Patient Consent.pdf";
            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
            return File(fs, "application/pdf");
        }