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

Passing results and ModelState Errors - grid does not bind result set...

1 Answer 408 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jim.Mills
Top achievements
Rank 1
Jim.Mills asked on 25 Jul 2013, 08:25 PM
I have a situation where I need to pass a message to be displayed along with the data for a grid.  I am attempting to do this in the _Read action (ajax).  I tried to place the message in ModelState, however, when I processed the error and pulled out the message, the grid did not bind the data that was sent.  Is there a way to pass additional data down to the client similar to passing additional data up to the client?

I did have a solution, where I set a property value on the first row and the client checked for that value and put up a message, but that only worked when there were results available to display - I may not send any data back (empty result set).

Thanks.




1 Answer, 1 is accepted

Sort by
0
Accepted
Petur Subev
Telerik team
answered on 29 Jul 2013, 08:40 AM
Hello Jim,

Basically this is not supported out-of-the-box. However you can extend the DataSourceResult and add additional field.

e.g.

public ActionResult GetPeople([DataSourceRequest] DataSourceRequest dsRequest)
{
    var dsResult = people.ToDataSourceResult(dsRequest);
    var result = new
    {
        dsResult.AggregateResults,
        dsResult.Data,
        dsResult.Errors,
        dsResult.Total,
        myMessage = "This message is retrieved from the server"
    };
    return Json(result);
}

On the client side you can use the requestEnd event of the dataSource to access that field send from the server.
e.g.
@(Html.Kendo().Grid<KendoMVCWrappers.Models.Person>().Name("people")
    .DataSource(dataSource => dataSource
        .Ajax()
            .Model(model => {
                model.Id(m => m.PersonID);
                model.Field(f => f.Name).Editable(false);
            })
            .Events(ev=>ev.RequestEnd(@"
                    function(e){
                        if(e.type=='read'){
                            alert(e.response.myMessage)
                        }
                    }"
                ))
//...

I hope this helps.

Kind Regards,
Petur Subev
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
Jim.Mills
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or