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

[Solved] No records to display message when using ajax binding

10 Answers 152 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Carey
Top achievements
Rank 1
Carey asked on 13 Sep 2011, 11:22 PM

Using the Grid with Ajax binding and the Entity Framework and specifying only the select method and action in the controller and view, the grid displays with the "No records to display message" even though the ajax bind method is called in the controller and the object that is created and assgined as the ajax method output is of the correct type.

I have a view with three grids, two of which are embedded in a tab strip.

Here is my view:
@{
    ViewBag.Title = "JobDetails";
}
  
<h2>JobDetails</h2>
  
@{
    
    Html.Telerik().Grid<DSAdmin.PROCESS_EXECUTION>()  //Grid((IEnumerable<DSAdmin.PROCESS_EXECUTION>)ViewData["Instances"])
            .Name("ExecutionInstances")
            .DataBinding(dataBinding => dataBinding
                .Ajax()
                    .Select("_Select_ExecutionInstance", "JobDetails", new { execID = ViewData["execID"] })) //, environment = ViewData["Environment"], mode = mode, type = type, pageInput = ViewData["pageInput"], nextPrevious = ViewData["nextPrevious"], numeric = ViewData["numeric"], position = position, currentPage = (int)ViewData["currentPage"], pageSize = ViewData["pageSize"] }))
            .Columns(columns =>
            {
  
                columns.Bound(o => o.EXECUTION_ID).Title("Execution ID").Width(100).ReadOnly(true);
                columns.Bound(o => o.PROCESS_OBJECT.OBJECT_NAME).Title("Process Name").Width(200).ReadOnly(true);
                columns.Bound(o => o.STATUS).Title("Status").Width(125);
                columns.Bound(o => o.START_TIME).Title("Start Time").Width(150).ReadOnly(true);
                columns.Bound(o => o.END_TIME).Title("End Time").ReadOnly(true);
            })
            .Render();    
    
      <p style="border:2px solid limegreen"> </p>
    Html.Telerik().TabStrip()
        .Name("details_tab")
        .Items(ts =>
            {
                ts.Add()
                    .Text("ETL Control")
                    .Content(@<text>
                    @{Html.Telerik().Grid<DSAdmin.ETL_CONTROL_TABLE>() //.Grid((IEnumerable<DSAdmin.ETL_CONTROL_TABLE>)ViewData["ETL_Control"])
                        .Name("ETL_Control")
                        .DataBinding(dataBinding => dataBinding
                            .Ajax()
                                .Select("_Select_JobDetails", "JobDetails", new { execID = ViewData["execID"]})) //, environment = ViewData["Environment"], mode = mode, type = type, pageInput = ViewData["pageInput"], nextPrevious = ViewData["nextPrevious"], numeric = ViewData["numeric"], position = position, currentPage = (int)ViewData["currentPage"], pageSize = ViewData["pageSize"] }))
                        .Columns(columns =>
                        {
  
                            columns.Bound(o => o.JOB_EXECUTION_ID).Title("Execution ID").Width(100).ReadOnly(true);
                            columns.Bound(o => o.PROCESS_NAME).Title("Process Name").Width(200).ReadOnly(true);
                            columns.Bound(o => o.STATUS).Title("Status").Width(125);
                            columns.Bound(o => o.START_TIME).Title("Start Time").Width(150).ReadOnly(true);
                            columns.Bound(o => o.END_TIME).Title("End Time").ReadOnly(true);
                        })
                        .Render();
                }
            </text>     
            );
                ts.Add()
                    .Text("Messages")
                    .Content(@<text>
                    @{Html.Telerik().Grid<DSAdmin.PROCESS_MESSAGE>() //.Grid((IEnumerable<DSAdmin.PROCESS_MESSAGE>)ViewData["Process_Message"])
                        .Name("Messages")
                        .DataBinding(dataBinding => dataBinding
                            .Ajax()
                                .Select("_Select_Messages", "JobDetails", new { execID = ViewData["execID"] })) //, environment = ViewData["Environment"],mode = mode, type = type, pageInput = ViewData["pageInput"], nextPrevious = ViewData["nextPrevious"], numeric = ViewData["numeric"], position = position, currentPage = (int)ViewData["currentPage"], pageSize = ViewData["pageSize"] }))
                        .Columns(columns =>
                        {
  
                            columns.Bound(o => o.MESSAGE_SEQUENCE_ID).Title("Execution ID").Width(100).ReadOnly(true);
                            columns.Bound(o => o.MESSAGE_TEXT).Title("Message").Width(850).ReadOnly(true);
                            columns.Bound(o => o.MESSAGE_TYPE_ID).Title("Type").ReadOnly(true);
                        })
                        .Render();
                    }
            </text>
            );
    })
    .SelectedIndex(0)
    .Render();
}
  
  
  
<script type="text/javascript">
      
      
      
</script>


Here is my controller:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DSAdmin;
using Telerik.Web.Mvc;
using Telerik.Web.Mvc.UI;
using System.Web.Routing;
using Telerik.Web.Mvc.Extensions;
using System.Diagnostics;
  
namespace DSAdmin.Controllers
{
    public class JobDetailsController : Controller
    {
  
        private BODS_ETL_CONTROLEntities db;
  
        private void SetConnection(String connection)
        {
            db = new BODS_ETL_CONTROLEntities(ConnectionHelper.GetConnectionString(connection));
        }
  
  
        public ActionResult JobDetails(int? execID)
        {
            return View();
        }
  
        [GridAction]
        public ActionResult _Select_ExecutionInstance(int? execID)
        {
            SetConnection("Sandbox");
            var pe = db.PROCESS_EXECUTION.Where(e => e.JOB_ID == 13);
            return View(new GridModel(pe));
        }
        [GridAction]
        public ActionResult _Select_JobDetails(int? execID)
        {
            SetConnection("Sandbox");
            var etl = db.ETL_CONTROL_TABLE.Where(e => e.JOB_ID == 13);
            return View(new GridModel(etl));
        }
        [GridAction]
        public ActionResult _Select_Messages(int? execID)
        {
            SetConnection("Sandbox");
            var pm =  db.PROCESS_MESSAGE.Where(e => e.PROCESS_OBJECT.OBJECT_ID == 44);
            return View(new GridModel(pm));
        }
         
    }
}


I have looked at the online examples and I do not see any difference. I also attahced a screen shot.


Thanks,

Carey

10 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 14 Sep 2011, 09:41 AM
Hello Carey,

I am afraid that we are not able to determine what might cause this. All the setup seems correct. If there are no errors the only reason I see is that
db.PROCESS_EXECUTION.Where(e => e.JOB_ID == 13) statement doesn't return any data. Can you please check this?

Greetings,
Rusev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Carey
Top achievements
Rank 1
answered on 14 Sep 2011, 05:08 PM
Hello,

I have verified that all three queries return data.  Here is a screen shot of one of them...


Carey
0
Carey
Top achievements
Rank 1
answered on 14 Sep 2011, 08:06 PM
Hi, would it matter if I was using the entity framework?  I am not getting any errors realted to the public navigation properties though.

Carey
0
Carey
Top achievements
Rank 1
answered on 14 Sep 2011, 09:04 PM
I have confirmed that it is related to the navigation properties on the entity framework even though no error is given.

I made all the nav props on the PROCESS_EXECUTION enity private and it now works...This is a real show stopper because it means you can't use the entity framework or you have to duplicate data models to have one with public nav properties and one with provate in order to use ajax.

Please tell me this is going to change :-)


Carey
0
Nikolay Rusev
Telerik team
answered on 15 Sep 2011, 12:57 PM
Hello Carey,

This seems to be related with the circular references in the model and the default JSON serializer. If you inspect the select request in the browser there will be error for the request. You can find more details and how to workaround this in the articles bellow.
http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-grid-troubleshooting.html#ServerError
http://www.telerik.com/community/code-library/aspnet-mvc/grid/using-custom-jsonresult-with-ajax-bound-grid.aspx

Regards,
Rusev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Carey
Top achievements
Rank 1
answered on 15 Sep 2011, 03:54 PM
Hello,

You are correct.  I traced the http requests and I get this below, HOWEVER I did add the maxJsonLength to web config and made no difference.  I will check the example project you also referenced :

<system.web.extensions>  
   <scripting>  
       <webServices>  
          <jsonSerialization maxJsonLength="2147483644" />
       </webServices>  
   </scripting>  
</system.web.extensions>


<html>
    <head>
        <title>A circular reference was detected while serializing an object of type 'DSAdmin.PROCESS_EXECUTION'.</title>
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
        </style>
    </head>
  
    <body bgcolor="white">
  
            <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1>
  
            <h2> <i>A circular reference was detected while serializing an object of type 'DSAdmin.PROCESS_EXECUTION'.</i> </h2></span>
  
            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">
  
            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
  
            <br><br>
  
            <b> Exception Details: </b>System.InvalidOperationException: A circular reference was detected while serializing an object of type 'DSAdmin.PROCESS_EXECUTION'.<br><br>
  
            <b>Source Error:</b> <br><br>
  
            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>
  
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>
  
                  </td>
               </tr>
            </table>
  
            <br>
  
            <b>Stack Trace:</b> <br><br>
  
            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>
  
[InvalidOperationException: A circular reference was detected while serializing an object of type 'DSAdmin.PROCESS_EXECUTION'.]
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1549
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +194
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +126
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1380
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +194
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +502
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1424
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +194
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +502
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1424
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +194
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +126
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1380
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +194
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeDictionary(IDictionary o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +527
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +1319
   System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +194
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +26
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat) +74
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj) +6
   System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context) +216
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
   System.Web.Mvc.Controller.ExecuteCore() +116
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8920029
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
</pre></code>
  
                  </td>
               </tr>
            </table>
  
            <br>
  
            <hr width=100% size=1 color=silver>
  
            <b>Version Information:</b> Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225
  
            </font>
  
    </body>
</html>
<!-- 
[InvalidOperationException]: A circular reference was detected while serializing an object of type 'DSAdmin.PROCESS_EXECUTION'.
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeDictionary(IDictionary o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj)
   at System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass1c.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
-->

Carey
0
Carey
Top achievements
Rank 1
answered on 15 Sep 2011, 04:02 PM
Hi,

I opened that sample project and it is using an older version of the MVC Extensions. 2011.1.414.  I am using the latest open source version 2011.2.712.  Will that make any difference?

Thanks
0
Carey
Top achievements
Rank 1
answered on 15 Sep 2011, 05:59 PM
OK, so I got it working however it still requires that we duplicate Entity Framework objects to use simple dto entities that are populated in place of the actual entities.  In this case I created PROCESS_EXECUTION_ajax to represent the simple dto form of the actual EF entity PROCESS_EXECUTION.  In fact, doing it this way does not require you to return Json at all but instead you can still use the default "View" as the return object.

Have a look at my code below for the View, Controller and dto entity definitions.

Controller:
public class JobDetailsController : Controller
    {
  
        private BODS_ETL_CONTROLEntities db;
  
        private void SetConnection(String connection)
        {
            db = new BODS_ETL_CONTROLEntities(ConnectionHelper.GetConnectionString(connection));
        }
  
  
        public ActionResult JobDetails(int? execID)
        {
            return View();
        }
  
        [GridAction]
        public ActionResult _Select_ExecutionInstance()
        {
            SetConnection("Sandbox");
            IEnumerable<PROCESS_EXECUTION_ajax> pe;
            pe =  db.PROCESS_EXECUTION.Where(o => o.JOB_ID == 13)
                  .Select(i => new PROCESS_EXECUTION_ajax
                    {
                        Execution_ID = i.EXECUTION_ID,
                        Process_ID = i.JOB_ID,
                        Start_Time = (DateTime)i.START_TIME,
                        End_Time = (DateTime)i.END_TIME,
                        Status = i.STATUS,
                        Execution_Type_ID = i.EXECUTION_TYPE_ID,
                        Process_Name = i.PROCESS_OBJECT.OBJECT_NAME
  
                    });
            return Json(new GridModel(pe));
        }
          
         
    }


View:
@model IEnumerable<DSAdmin.PROCESS_EXECUTION>
@{
    ViewBag.Title = "JobDetails";
}
  
<h2>JobDetails</h2>
  
@{
    
    Html.Telerik().Grid<DSAdmin.PROCESS_EXECUTION_ajax>()
            .Name("ExecutionInstances")
            .DataBinding(dataBinding => dataBinding
                .Ajax()
                    .Select("_Select_ExecutionInstance", "JobDetails"))
              .Scrollable()
              .Sortable()
              .Pageable(o =>
              {
                  o.Position(GridPagerPosition.Bottom);
                  o.Style(GridPagerStyles.NextPreviousAndDropDown | GridPagerStyles.PageSizeDropDown | GridPagerStyles.PageInput);
                  o.Enabled(true);
              })
              .Columns(columns =>
            {
                columns.Bound(o => o.Execution_ID).Title("Execution ID").Width(100).ReadOnly(true);
                columns.Bound(o => o.Process_Name).Title("Process Name").Width(200).ReadOnly(true);
                columns.Bound(o => o.Status).Title("Status").Width(125);
                columns.Bound(o => o.Start_Time).Title("Start Time").Width(150).ReadOnly(true);
                columns.Bound(o => o.End_Time).Title("End Time").Width(150).ReadOnly(true);
                columns.Bound(o => o.Execution_Type_ID).Title("Exec Type").ReadOnly(true);
            })
            .Render();    
    
        
}


DTO PROCESS_EXECUTION_ajax entity:
public class PROCESS_EXECUTION_ajax
    {
        public PROCESS_EXECUTION_ajax() { }
          
        private int _Execution_ID;
  
        public int Execution_ID
        {
            get { return _Execution_ID; }
            set { _Execution_ID = value; }
        }
          
        private int _Execution_Type_ID;
  
        public int? Execution_Type_ID
        {
            get { return _Execution_Type_ID; }
            set { _Execution_Type_ID = value ?? -1; }
        }
        private int _Process_ID;
  
        public int? Process_ID
        {
            get { return _Process_ID; }
            set { _Process_ID = value ?? -1; }
        }
        private String _Process_Name;
  
        public String Process_Name
        {
            get { return _Process_Name; }
            set { _Process_Name = value; }
        }
        private DateTime _Start_Time;
  
        public DateTime Start_Time
        {
            get { return _Start_Time; }
            set { _Start_Time = value; }
        }
        private DateTime _End_Time;
  
        public DateTime End_Time
        {
            get { return _End_Time; }
            set { _End_Time = value; }
        }
        private String _Status;
  
        public String Status
        {
            get { return _Status; }
            set { _Status = value; }
        }
  
         
  
    }


This works perfectly fine however still requires duplication of your entities that you want to participate in Ajax binding.  To simplify the DTO entity creation you can use the Visual Studio POCO generator extensions and then strip out any of the entity related parts to have a simple property only version of each of your EF entities.

It would be great if this can be taken care of automatically somehow otherwise it might make using the EF a bit cumbersome and I really like the EF and the Telerik controls :-)


Thanks,

Carey
0
Accepted
Nikolay Rusev
Telerik team
answered on 16 Sep 2011, 11:37 AM
Hello Carey,

I am afraid that this isn't in our control. The possible actions in this case is to use projection of the real model(as you already did) or implement custom JavaScriptSerializer. You can find demo for the latter in the following forum thread.
http://www.telerik.com/community/forums/aspnet-mvc/grid/dynamic-object-ajax-binding-issue.aspx#1739384

All the best,
Nikolay Rusev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Reid
Top achievements
Rank 2
answered on 21 May 2012, 05:30 PM
Hello Nikolay,

This is an old thread but I wanted to comment, as I just discovered the EF classes are not compatible with the model binder.  I knew this was true for classes used across the wire in WCF but was not sure about the MVC Model Binder. 

If you inspect the Html in the Console tab of FireBug you can see the error that states the serialization problem.  Actually it pointed to a different class that was not in the ViewModel but was the first class in the EF that it could not serialize.

Reid
Tags
Grid
Asked by
Carey
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Carey
Top achievements
Rank 1
Reid
Top achievements
Rank 2
Share this question
or