This is a migrated thread and some comments may be shown as answers.

OData 406 Not Acceptable

1 Answer 196 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gaines Kergosien
Top achievements
Rank 1
Gaines Kergosien asked on 13 Feb 2015, 03:18 PM
I've been struggling to get OData results to show up in Kendo Grid without luck. Even when I would get the endpoint returning a JSON result set, the grid still would fail to display any records. I can also save new records, although the grid gets back a 406 message and does not realize the record was successfully saved.

public class ListController<TObject> : ApiController where TObject : class, IListItem
{
    [Queryable]
    public IEnumerable<TObject> Get()
    {
        var results = _repository.GetAll();
        return results.AsEnumerable();
    }

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services
        var cors = new EnableCorsAttribute("*", "*", "*");
        config.EnableCors(cors);
        config.EnableCaseInsensitive(true);
        config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling =
            Newtonsoft.Json.PreserveReferencesHandling.All;
 
        // Web API routes
        config.MapHttpAttributeRoutes();
 
        //config.Routes.MapHttpRoute(
        //    name: "DefaultApi",
        //    routeTemplate: "api/{controller}/{id}",
        //    defaults: new { id = RouteParameter.Optional }
        //);
 
        ODataModelBuilder builder = new ODataConventionModelBuilder();
        builder.EntitySet<LotStatus>("lotstatuses");
        config.MapODataServiceRoute(
            routeName: "odata",
            routePrefix: "",
            model: builder.GetEdmModel());
 
    }
}

<script>
    var remoteDataSource = new kendo.data.DataSource({
        batch: false,
        serverPaging: true,
        serverSorting: true,
        serverFiltering: true,
        type: "odata",
        transport: {
            read: {
                url: "http://localhost:55097/lotstatuses",
                dataType: "json",
                //contentType: "application/json"
            },
            create: {
                url: "http://localhost:55097/lotstatuses",
                dataType: "json",
                contentType: "application/json",
                type: "POST"
            },
            update: {
                url: "http://localhost:55097/lotstatuses",
                dataType: "json",
                contentType: "application/json",
                type: "PUT"
            },
            destroy: {
                url: "http://localhost:55097/lotstatuses",
                dataType: "json",
                contentType: "application/json",
                type: "DELETE"
            },
            parameterMap: function (options, operation) {
                var paramMap = kendo.data.transports.odata.parameterMap(options);
                delete paramMap.$inlinecount; // <-- remove inlinecount parameter
                delete paramMap.$format; // <-- remove format parameter
 
                return paramMap;
            }
        },
        schema: {
            data: function (data) {
                return data.value;
            },
            total: function (data) {
                return data["odata.count"];
            },
            errors: function (data) {
            },
            model: {
                id: "Code",
                fields: {
                    Code: { type: "string", editable: true, nullable: false, validation: { required: true } },
                    Name: { type: "string", editable: true, nullable: false, validation: { required: true } }
                }
            }
        }
    });
    $('#grid').kendoGrid({
        dataSource: remoteDataSource,
        height: 500,
        toolbar: [{ name: "create", text: "Create new Lot Status" }],
        filterable: true,
        sortable: true,
        pageable: true,
        editable: "popup",
        columns: [
                { field: "Code",  title: "Code" },
                { field: "Name", title: "Name" },
                { command: ["edit", "destroy"] }
        ]
    });
</script>

If I could just find an example of an OData v4 service project that works with Kendo Grid I'm pretty sure I could figure this out. Anyone?

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 17 Feb 2015, 09:38 AM
Hi Gaines,

You can find an example of using Kendo UI Grid widget bound to an ApiController using OData v4 in this GitHub repository.

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Gaines Kergosien
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or