ASP.NET MVC

<< Click to Display Table of Contents >>

Navigation:  Gnostice Document Studio .NET > Going Deeper > Document Viewing > ASP.NET > Displaying server-side documents >

ASP.NET MVC

Steps to load the document from server in an ASP.NET MVC application is listed as follows.

1.Setup a simple document viewer control in ASP.NET MVC application as explained in the Getting Started section.

2.Copy input document to App_Data folder in your application.

3.In the controller class, add/replace  the below method

 

    public ActionResult Index()
    {
        Gnostice.Controls.ASP.ViewerController viewerController = 

            new Gnostice.Controls.ASP.ViewerController();
        // Load the file present under App_Data folder
        String filenameWithPath = Server.MapPath(".") + "\\App_Data\\sampleFormDocument.pdf";
        // Load the server-side document using the document URI
        ViewBag.docURI = viewerController.LoadDocument(filenameWithPath);
        return View();
    }

 

         

This method is invoked before loading the webpage. Here ViewerController is initialized and the document is loaded through ViewerController.

4.In client side, add below JavaScript code snippet to <body> section of view page to load the document

 

    <script type="text/javascript">
    var documentViewer = null;
    $(function () {
        var docURI = '@ViewBag.docURI';
        if(docURI != null) {
            // Load the server-side document using its URI
            documentViewer.loadDocument(docURI);
        }
    });
    </script>

 

         

The above JavaScript method is invoked when the web page is ready to view the document in the viewer. The document is loaded by using the document URI sent by the controller.

5.Run the application in your favorite browser.