简体   繁体   中英

Get value from Web Api Controller in ASP.NET page

I have a web api controller GET api method in which I call an external REST service to fetch data. I want to show a piece of data (a property from my data model class to hold the external web service data) on asp.net page. The api controller calls a method of a repository class library where I fetch the data from the external REST service and return in my web api controller.

I call my web api contoller get api method in a javascript on the ASP.NET page where I use the PDF Tron web viewer control.

<script src="settings.js"></script>

I don't want to use Session (though Session is not available, workarounds are available to use Session) as it would make my REST api stateful.

Please advise on what options are available to fetch data from a web api controller in asp.net page.

//Settings.js code

window.WebViewerUniversalInstance.model.set(
{     
    documentUrl: "/api/Document/?type=XOD&docno=101",    
    //serverUrl: "../html5/annotationHandler.php",    //server script for handling annotations
    annotationUser: new PDFTron.WebViewer.User("Guest", false),
    currentPageNumber: 0,
    pageCount: 0,
    zoomLevel: 0,
    fitMode: PDFTron.WebViewer.FitMode.Zoom,
    layoutMode: PDFTron.WebViewer.LayoutMode.SinglePage,
    toolMode: '',
    rotation: 0,
    webViewerLibPath: 'lib/', //URL path to the WebViewer lib folder
    webViewerOptions: { //extra WebViewer options
        silverlightOptions: {
            enableAnnotations: false //disable annotations if silverlight is loaded. 
            }
        }
    }
);

The documentUrl option is just a helper method, and cannot be overloaded like you are trying to do.

If you want to optimize to a single server call, then you would do this manually your self, just as you would normally make any server request using ASP.Net.

So in response to

/api/Document/?type=XOD&docno=10

your server could return some sort of response like below.

{
  xodurl: url,
  metadata1: data1,
  metadata2: data2
}

You would then pass the url parameter to the WebViewer documentUrl parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM