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

Grid DataSource (using Razor) Specify URL

3 Answers 489 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 1
Bob asked on 28 Nov 2013, 04:17 PM
Using Razor syntax with the Grid Data Source, I am trying to specify a valid URL.

I see the documentation recommends the syntax of   

.Read(read => read.Action("Orders_Read", "Grid"))

I want to use a url for an API that I use in the app that looks like "/Orders_read/Grid/id/1/office/2"

Do you have any razor examples of passing in the URL instead of the Action/Controller?  

3 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 02 Dec 2013, 09:30 AM
Hello Bob,

In that scenario I would recommend using the Url method. In case you expect to have some dynamic values that need be sent to the Controller as form data, then you might find the Data method useful as well. 

Regards,
Alexander Popov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Bob
Top achievements
Rank 1
answered on 03 Dec 2013, 01:12 AM
Can you help me fix this Grid example that I am using>
@(Html.Kendo().Grid<model>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.nPrivate);
        columns.Bound(p => p.nSticky).Width(100);
        columns.Bound(p => p.nAbstract).Width(100);
        columns.Bound(p => p.nMemo).Width(100);
        columns.Bound(p => p.nDateTime).Width(100);
        columns.Bound(p => p.nInitials).Width(100);
        columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);
    })
    .ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:430px;" })
.DataSource(dataSource => dataSource
        .Ajax()
        .PageSize(20)
        .Events(events => events.Error("error_handler"))
        .Model(model => model.Id(p => p.nMemoID))
        .Create(update => update.Url("http://localhost:2/api/memo/a/8"))
        .Read(read =>  read.Url("http://localhost:2/api/memos/all/8"))
        .Update(update => update.Url("http://localhost:2/api/memos/all/8"))
        .Destroy(update => update.Url("http://localhost:2/api/memos/all/8"))
    )

Via Fiddler, I do see that the Read URL is hit and JSON data is returned.  However, the JSON is not populated in the grid
How do I tell the grid wrapper its json?  via a Data attribute you mentioned?  Any example?
0
Alexander Popov
Telerik team
answered on 04 Dec 2013, 03:08 PM
Hi Bob,

The Grid expects the JSON data to arrive wrapped in an array of objects called Data, for example: 
{
    "Data": [{
        "ProductID": 1,
        "ProductName": "Chai8",
        "UnitPrice": 18.00,
        "UnitsInStock": 39,
        "Discontinued": false
    }, {
        "ProductID": 2,
        "ProductName": "Chang",
        "UnitPrice": 19.00,
        "UnitsInStock": 17,
        "Discontinued": false
    }],
    "Total": 2,
    "AggregateResults": null,
    "Errors": null
}
When the Grid is initialized using JavaScript you can change that behavior using the schema.data option, however KendoUI for ASP.NET MVC uses a slightly different schema and you have no control over what the Grid expects.
In the current scenario I would recommend you to make sure the data arrives in the format shown above. You can find additional information in the Grid Ajax binding article.

Regards,
Alexander Popov
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
Bob
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Bob
Top achievements
Rank 1
Share this question
or