[英]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. 我有一个Web API控制器GET api方法,在其中调用外部REST服务以获取数据。 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.
我想在asp.net页面上显示一条数据(数据模型类的一个属性,用于保存外部Web服务数据)。 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.
api控制器调用存储库类库的方法,在该方法中,我从外部REST服务获取数据并返回我的Web api控制器。
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. 我在ASP.NET页面上的JavaScript中使用Java Web PDF contoller get api方法,在该页面上我使用PDF Tron Web Viewer控件。
<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. 我不想使用Session(尽管Session不可用,但可以使用Session解决方法),因为这会使我的REST api处于有状态。
Please advise on what options are available to fetch data from a web api controller in asp.net page. 请在asp.net页面上告知可使用哪些选项从Web api控制器获取数据。
//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. documentUrl选项只是一个辅助方法,不能像您尝试的那样重载。
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. 如果要优化为单个服务器调用,则可以自行完成此操作,就像通常使用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. 然后,您可以将url参数传递给WebViewer documentUrl参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.