• OData V4 系列 Action 与 Function


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

                 

  • 相关阅读:
    Java中IO流的总结
    Java常用集合体系以及相互区别
    TreeMap集合特点、排序原理
    HashMap集合
    TreeSet集合
    redis 数据类型详解 以及 redis适用场景场合
    You need tcl 8.5 or newer in order to run the Redis test
    PHP 获取二维数组中某个key的集合
    Linux 定时任务
    phpmailer邮件类
  • 原文地址:https://www.cnblogs.com/Fengger/p/4960353.html
Copyright © 2020-2023  润新知