OData V4 系列 Action 與 Function

       OData 學習目錄html

       瞭解過WebApi的都知道,WebApi默認方法 Get、Post、Put,若是增長其它過多Post方法即不能識別,還需增長其它配製,請求的Url還需加上Controller及Action,與Restful設計不一致,Odata能夠解決這樣的問題。ajax

    配製路由服務       json

            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 會出現以下錯誤
         app

              修改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;
                }
            });
相關文章
相關標籤/搜索