2014-07-22 3 views
0

좋아, 이제 내 로프 끝에 있습니다. 나는 내가 발견 할 수있는 모든 예를보고 봤고 아무것도 복사하지 않았다.검도 그리드가 OData 컨트롤러와 함께 작동하지 않습니다.

public async Task<IHttpActionResult> GetRecipeOData(ODataQueryOptions<Recipe> queryOptions) 
     { 
      // validate the query. 
      try 
      { 
       queryOptions.Validate(_validationSettings); 
      } 
      catch (ODataException ex) 
      { 
       return BadRequest(ex.Message); 
      } 


      RecipeContext rc = new RecipeContext();    

      return Ok<IQueryable<Recipe>>(rc.Recipes.AsQueryable()); 
      //return StatusCode(HttpStatusCode.NotImplemented); 
     } 

검도 그리드 :

var initRecipesGrid = function() { 
      $("#recipesGrid").kendoGrid({ 
       dataSource: { 
        type: "odata", 
        transport: { 
         read: "odata/RecipeOData", 
        } 
       }, 
       height: 550, 
       groupable: true, 
       sortable: true, 
       pageable: { 
        refresh: true, 
        pageSizes: true, 
        buttonCount: 5 
       }, 
       columns: [{ 
        field: "Label", 
        title: "Recipe Name" 
       },{ 
        field: "OriginalGravity", 
        title: "O.G." 
       },{ 
        field: "FinalGravity", 
        title: "F.G." 
       }] 
      }); 
     } 

다음 요청 :

HTTP/1.1 200 OK 
Cache-Control: no-cache 
Pragma: no-cache 
Content-Type: application/json; charset=utf-8 
Expires: -1 
Server: Microsoft-IIS/8.0 
DataServiceVersion: 3.0 
X-AspNet-Version: 4.0.30319 
X-SourceFiles: =?UTF-8?B?Qzpcd29ya3NwYWNlXEJlZXJSZWNpcGVcQmVlclJlY2lwZVdlYlxvZGF0YVxSZWNpcGVPRGF0YQ==?= 
X-Powered-By: ASP.NET 
Date: Tue, 22 Jul 2014 02:03:22 GMT 
Content-Length: 836 

{ 
    "odata.metadata":"http://localhost:25189/odata/$metadata#RecipeOData","value":[ 
    { 
     "Label":"NewCrazy Icelandic Porter","SubmittedById":"b31452d1-d8d7-480c-aa9c-4e298da0054e","StyleId":6,"Notes":"Love this beer","OriginalGravity":1.057,"FinalGravity":1.012,"YeastId":635,"SubmittedOn":"2014-07-17T22:05:59.967" 
    },{ 
     "Label":"NewSome Crazy Amber Ale","SubmittedById":"b5166f3a-b278-4f2c-8ec5-12376de48405","StyleId":4,"Notes":"Great taste, less filling","OriginalGravity":1.057,"FinalGravity":1.012,"YeastId":1027,"SubmittedOn":"2014-07-17T22:10:17.667" 
    },{ 
     "Label":"NewCrazy Icelandic Porter","SubmittedById":"30f22f2f-6f28-4a16-8dc8-f3f837887e88","StyleId":9,"Notes":"Love this beer","OriginalGravity":1.057,"FinalGravity":1.012,"YeastId":763,"SubmittedOn":"2014-07-17T22:10:29.353" 
    } 
    ] 
} 
:

GET http://localhost:25189/odata/RecipeOData?$callback=jQuery21109926259643398225_1405994583958&%24inlinecount=allpages&%24format=json 

는 다음과 같은 응답을 반환 여기

컨트롤러 액션 내 설정이다

"error"함수를 dataSource에 추가 했으므로 오류를 기록합니다. 다음과 같은 메시지가 나타납니다.

object {xhr: Object, status: "parsererror", errorThrown: SyntaxError, sender: ct.extend.init, _defaultPrevented: false…} 
_defaultPrevented: false 
errorThrown: SyntaxError 
message: "Unexpected token :" 
stack: "SyntaxError: Unexpected token :↵ at eval (native)↵ at Function.jQuery.extend.globalEval (http://localhost:25189/Scripts/jquery-2.1.1.js:330:5)↵ at jQuery.ajaxSetup.converters.text script (http://localhost:25189/Scripts/jquery-2.1.1.js:8654:11)↵ at ajaxConvert (http://localhost:25189/Scripts/jquery-2.1.1.js:7786:19)↵ at done (http://localhost:25189/Scripts/jquery-2.1.1.js:8201:15)↵ at XMLHttpRequest.<anonymous> (http://localhost:25189/Scripts/jquery-2.1.1.js:8598:9)" 
get stack: function() { [native code] } 
set stack: function() { [native code] } 
__proto__: Error 
isDefaultPrevented: function(){return this._defaultPrevented===!0} 
preventDefault: function(){this._defaultPrevented=!0} 
sender: ct.extend.init 
status: "parsererror" 
xhr: Object 
__proto__: Object 

답변

0

잘못된 데이터 소스 구성을 중첩했습니다. 나는 다음과 같이 그것을 필요로했다 :

transport: { 
    read: { 
     url:"odata/RecipeOData", 
     dataType: "json" 
    } 
관련 문제