【问题标题】:Scaffolded Upshot context not calling webapi?脚手架 Upshot 上下文不调用 webapi?
【发布时间】:2012-06-04 19:52:06
【问题描述】:

我正在关注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 我得到了预期的结果。 (并且断点被命中)

我似乎无法弄清楚脚手架的结果脚本发生了什么。

谢谢

【问题讨论】:

    标签: javascript asp.net-mvc asp.net-mvc-4 asp.net-web-api upshot


    【解决方案1】:

    试试下面的代码:

    dataSource.refresh(function (entities, total){
       alert(entities);
    });
    

    另外,进入firebug/开发者控制台的Network选项卡,或者启动Fiddler,查看对控制器的请求是否真的发送出去了。如果已发送,则您的问题出在控制器上,可能未正确映射操作。

    【讨论】:

      猜你喜欢
      • 2020-05-28
      • 2019-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-07
      • 1970-01-01
      • 1970-01-01
      • 2015-02-13
      相关资源
      最近更新 更多