首页 > 其他 > 详细

OData V4 系列 Action 与 Function

时间:2015-11-12 23:30:19      阅读:412      评论:0      收藏:0      [点我收藏+]

       OData 学习目录

       了解过WebApi的都知道,WebApi默认方法 Get、Post、Put,如果增加其它过多Post方法即不能识别,还需增加其它配制,请求的Url还需加上Controller及Action,与Restful设计不一致,Odata可以解决这样的问题。

    配制路由服务       

            builder.Namespace = "ProductService";
            builder.EntityType<Product>().Collection
                .Function("MostExpensive")  //函数路由
                .Returns<double>();

            builder.Namespace = "ProductService";
            builder.EntityType<Product>()
                .Action("Rate")  //Action路由
                .Parameter<int>("Rating");

         通过Get请求 MostExpensive 会出现如下错误
         技术分享

              修改Web.config   <modules runAllManagedModulesForAllRequests="true"></modules>

              技术分享

              技术分享

               Action 请求              

              $.ajax({
                url: "/Odata/Products(" + id + ")/ProductService.Rate",
                type: "POST",
                contentType: "application/json; charset=utf-8",
                dataType: "JSON",
                data: JSON.stringify({ Rating: 5 }),
                success: function (r) {
                    debugger;
                },
                error: function (e) {
                    debugger;
                }
            });

 

             

 

OData V4 系列 Action 与 Function

原文:http://www.cnblogs.com/Fengger/p/4960353.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!