Scaffolded Upshot context not calling webapi?

428 Views Asked by At

I am following a very simple tutorial by Steve Sanderson and it seems like the scaffolded script does not call my webapi:

cshtml code:

@(Html.UpshotContext().DataSource<Yoga.Controllers.YogaController>(x => x.GetAllBugs()))

Generated script:

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: {}
});

and it was called after page is loaded:

        $(function() {
        var dataSource = upshot.dataSources.AllBugs;
        dataSource.refresh(function(results)){
        //error here, `result` is an null object
            alert(results);
        });
    });

I placed a breakpoint at my GetAllBugs() member in the controller, and it was never hit.

However, when i visit the uri directly, http://localhost/api/yoga/getallbugs i get the expected result. (and the breakpoint was hit)

I can't seem to figure out what is going on with the scaffolded upshot script.

Thanks

1

There are 1 best solutions below

0
On

Try the following code:

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

Also, go to the Network tab of firebug/developer console, or start up Fiddler, and check whether the request to the controller is actually sent or not. If it is sent, then your problem is on controller, probably not mapping the action correctly.