0

I would like to try this

Telerik Grid throw a circular reference exception when I try to use an entityframework poco class into his binding. The code mentioned in the link propose to replace the json serializer used by Telerik with the NewtonSoft one. But Telerik Grid never call the create method from CustomGridActionResultFactory injected into the Grid. Does someone know the problem about this code (link above)?

Community
  • 1
  • 1
Francis
  • 486
  • 3
  • 21

3 Answers3

0

If you like me, think that creating a separate view models just for the telerik grid is overkill, you could feed your own Json to the grid created from a list of anonymous objects:

//This goes in the View:
Html.Telerik().Grid(Model)
    .Name("Grid")
    .Columns(columns =>
    {
    // your column mappings go here
    })
    .DataBinding(dataBinding => dataBinding.Ajax().Select("_yourMethodReturningJson", "YourControllerName", new { yourJsonMethodParameter = yourViewModel.someField }))
    .Pageable()
    .Sortable()
    .Render();

And the Json method in your controller looks like this:

    public JsonResult _yourMethodReturningJson(YourType? yourJsonMethodParameter)
    {
        var list = database.SomeCollection.Select(x => new
            {
                SomeColumnName = x.SomeField
            });
        return Json(list, JsonRequestBehavior.AllowGet);

    }

Your could use a better Json library here if you like: http://james.newtonking.com/pages/json-net.aspx

Zar Shardan
  • 5,675
  • 2
  • 39
  • 37
0

There is a code library project which shows how to create a custom GridActionResultFactory. You may find it helpful.

Atanas Korchev
  • 30,562
  • 8
  • 59
  • 93
0

You should use a "special" View Model for the TelerikGrid.

For examle if you use a Database Model something like this

public class Master {  
    public int Id { get; set; }  
    public string Name { get; set; }  
    public List<Detail> Details { get; set; }   
}  

public class Detail {  
    public int Id { get; set; }  
    public string Name { get; set; }  
    public Master Master { get; set; }   
}  

You need to create View Model as given below

public class MasterView {  
    public int Id { get; set; }  
    public string Name { get; set; }   
}  

public class DetailView {  
    public int Id { get; set; }  
    public string Name { get; set; }  
    public int MasterId { get; set; }   
}  
adyusuf
  • 806
  • 1
  • 11
  • 27