opening PDF file in iframe on certain page

Viewed 1711

I have an iframe which uses a Url.Action to open a PDF from an action controller. Is it possible to open this PDF on a certain page? Determined by a value in the model e.g. @Model.FilePage

iframe:

        <iframe width="700" height="1600" src="@Url.Action("OpenPDF", new { id = 8 })"></iframe>

controller action:

public ActionResult OpenPDF(int? id)
        {
            CompletedCamp completedCamp = db.CompletedCamps.Find(id);
            string filepath = Server.MapPath(Path.Combine("~/Surveys/" + completedCamp.SurveyName));
            return File(filepath, "application/pdf");
        }
1 Answers

To open on specific page, add #page=[page number] to the end of src

<iframe width="700" height="1600" src="@Url.Action("OpenPDF", new { id = 8 })#page=4"></iframe>

if page number should be from the model, do

public ActionResult Index()
{
    MyViewModel m = new MyViewModel() { FilePage = 4 }; 
    return View(m);
}

...
@model MVC.MyViewModel 

<iframe width="700" height="1600" src="@Url.Action("OpenPDF", new { id = 8 })#page=@Model.FilePage"></iframe>
Related