我遵循了Steve Sanderson的一个非常简单的教程,看起来脚手架脚本并没有调用我的webapi:
cshtml代码:
@(Html.UpshotContext().DataSource<Yoga.Controllers.YogaController>(x => x.GetAllBugs()))
生成的脚本:
upshot.dataSources = upshot.dataSources || {};
upshot.metadata({...});
upshot.dataSources.AllBugs = upshot.RemoteDataSource({
providerParameters: { url: "/api/Yoga/", operationName: "GetAllBugs" },
entityType: "BugView:#Yoga.Models",
bufferChanges: false,
dataContext: undefined,
mapping: {}
});它是在页面加载后调用的:
$(function() {
var dataSource = upshot.dataSources.AllBugs;
dataSource.refresh(function(results)){
//error here, `result` is an null object
alert(results);
});
});我在控制器中的GetAllBugs()成员处放置了一个断点,但它从未命中。
但是,当我直接访问uri时,http://localhost/api/yoga/getallbugs得到了预期的结果。(并且命中了断点)
我似乎弄不明白脚手架的结束语是怎么回事。
谢谢
发布于 2012-06-04 19:52:06
尝试以下代码:
dataSource.refresh(function (entities, total){
alert(entities);
});此外,转到firebug/开发人员控制台的Network选项卡,或启动Fiddler,并检查发送到控制器的请求是否已实际发送。如果它被发送了,那么您的问题出在控制器上,可能没有正确地映射操作。
https://stackoverflow.com/questions/10727497
复制相似问题