结果绑定到Web API中不同的项目 [英] Binding upshot to a Web API in a different project

查看:95
本文介绍了结果绑定到Web API中不同的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个应用程序SPA,采取的结果的优势和它的功能。然而,暴露的数据(即在Web API)服务是一个完全独立的项目,已经托管于IIS。我想绑定结果到现有的API,但是从我可以在HTML佣工的结果(V1.0.0.1)看看,你需要一个公开的数据,像这样的控制器的类型来传递:

I am trying to create a SPA application, to take advantage of upshot and its capabilities. However, the services exposing the data (i.e. the Web API) is in a completely separate project, already hosted on IIS. I would like to bind upshot to that existing API, but from what I can see in the HTML helpers for upshot (v1.0.0.1), you need to pass in the type of the controller that exposes the data, like so:

Html.UpshotContext.DataSource(中的 ToDoController )(功能(X)x.GetTodoItems())

Html.UpshotContext.DataSource(Of ToDoController)(Function(x) x.GetTodoItems())

其中的 ToDoController 的是,公开数据ApiController,在同一个项目中定义。

where ToDoController is the ApiController that exposes the data, defined in the same project.

我的问题是,我该怎么绑定结果到Web API,它是不是在同一个项目?
有什么办法,我可以使用的帮手,否则我将不得不手工做的一切?

My question is, how can I bind upshot to a Web API that is not in the same project? Is there any way I can use the helpers, or will I have to do everything manually?

我有机会获得Model类(即内的TodoItem ),因为他们是在一个单独的程序,它可以从两个项目中引用(SPA&安培;网页API),但我不访问在Web API项目定义的控制器。

I have access to the Model classes (i.e. TodoItem), as they are in a separate assembly, which can be referenced from both projects (SPA & Web API), but I don't have access to the controllers defined in the Web API project.

推荐答案

您可以使用以下方法:

upshot.dataSources = upshot.dataSources || {};

upshot.metadata({"ModelType:#Namespace":
    {
     "key":["Id"],
     "fields":    
        {"Id":{"type":"Int32:#System"},
         "IpAddress":{"type":"String:#System"},
         "Name":{"type":"String:#System"}
        }
    } (and so on, just map everything)
});

var dataSource = new upshot.RemoteDataSource({
    providerParameters: 
        { url: "Your URL", 
          operationName: "Method Name, example: GetCustomers" },
    entityType: "ModelType:#Namespace",
    bufferChanges: true (or false, whatever you like),
    dataContext: undefined,
    mapping: {}
});

如果我是你,如果我能我将暂时建立在它的控制器项目的解决方案,那么我会检查由 UpshotContext 帮手产生的JS和复制那到你的页面(这是我做过什么有上述结果,反正)。

If I were you, If I could I would temporarily create a solution with the Controller project in it, then I would check the JS generated by the UpshotContext helper and copy that into your pages (which is what I did to have the result above, anyway).

这篇关于结果绑定到Web API中不同的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆