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

[Solved] Internal error 500

2 Answers 238 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.
dani
Top achievements
Rank 1
dani asked on 13 Jan 2011, 07:23 AM
** UPDATE **
I've cleared this issue by creating a POCO List instead of using the objects from the DB (with EF4)
Is this the only way to use Telerik's Grid with EF4 objects with reference ?)

I see the AJAX call to the controller, and the return has a list inside it.
yet I get 500 Internal error:
What can it be ?

here is the view and controller code:
ItemsInOrder is a EF4 entity that represet a table with compound key (orderID and ItemID)

UPDATE: this is the server response:
The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.
I've tried also:
[GridAction]
       public ActionResult SelectItemGridAjax(int OrderID)
       {
           return View(new GridModel(ordersRepository.GetOrderItemsTK(OrderID).ToList()));
       }

but it didn't help. this is what the repository sends back:
              var  result = (from p in context.ItemsInOrders.Include("Order").Where(i=>i.OrderID == OrderID) select p).ToList();


Help will be appreciated...


On this view
<%=
                Html.Telerik().Grid<ItemsInOrder>()     
                    .Name("ItemsInOrderGrid")
                                    .DataKeys(dataKeys =>
                                    {
                                        dataKeys.Add(e => e.OrderID);
                                        dataKeys.Add(e => e.ItemID);
                                    })
 
                    .ToolBar(commands => commands.Insert())
                    .DataBinding(dataBinding =>
                        {
                        dataBinding.Ajax()    //Ajax binding
 
                .Select("SelectItemGridAjax", "Orders", new { OrderID = Model.myOrder.OrderID })
                .Insert("InsertItemGridAjax", "Orders", new { OrderID = Model.myOrder.OrderID })
                .Update("UpdateItemGridAjax", "Orders")
                .Delete("DeleteItemGridAjax", "Orders");
                        })
                    .Columns(c =>
                        {
                            c.Bound(o => o.ItemID);
                            c.Bound(o => o.OrderID).Column.Visible = false;
                            c.Bound(o => o.ItemDescription);
                            c.Bound(o => o.NumOfItems);
                            c.Bound(o => o.CostOfItem);
                            c.Bound(o => o.TotalCost);
                            c.Bound(o => o.SupplyDate);
                            c.Command(commands =>
                                {
                                    commands.Edit();
                                    commands.Delete();
                                }).Width(180).Title("?????");
                        })
            %>

I get
POST SelectItemGridAjax?OrderID=2
http://localhost:6105/Orders/SelectItemGridAjax?OrderID=2
500 Internal Server Error

with this controller - I can see the ajax call reaching the controller, and the return has a list with 2 items on it.
[GridAction]
  public ActionResult SelectItemGridAjax(int OrderID)
  {
      return View(new GridModel(ordersRepository.GetOrderItemsTK(OrderID)));
  }

it also happens on the rest of the functions... (Insert, delete, Update):
POST InsertItemGridAjax?OrderID=2
http://localhost:6105/Orders/InsertItemGridAjax?OrderID=2
500 Internal Server Error

[AcceptVerbs(HttpVerbs.Post)]
   [GridAction]
   public ActionResult InsertItemGridAjax(int OrderID)
   {
       //Create a new instance of the EditableCustomer class.
       ItemsInOrder newItem = ItemsInOrder.CreateItemsInOrder(OrderID, "");
       newItem.OrderID = OrderID;
 
       //Perform model binding (fill the customer properties and validate it).
       if (TryUpdateModel(newItem))
       {
           //The model is valid - insert the customer.
           bool res = ordersRepository.InsertItemToOrder(OrderID, newItem);
       }
 
       //Rebind the grid
       return View(new GridModel(ordersRepository.GetOrderItemsTK(OrderID)));
   }

2 Answers, 1 is accepted

Sort by
0
Corey Gaudin
Top achievements
Rank 1
answered on 01 Feb 2011, 03:39 PM
I am having the exact same issue with a normal EF4 Model Object and a CodeFirst Model Object. It simply does not work in Ajax request modes. Is there any plans to fix this going forward? Because creating a DTO Object for every Model that is already like I need it and have to maintain properties and values in 2 different places, not to mention Data Annotations would get old real quick.

Any time I get back any object that is an Data Entity Model Object from Entity Framework 4 through the Ajax request, it returns a 500 Internal Error. Please reply. Is this being looked at?
0
Atanas Korchev
Telerik team
answered on 01 Feb 2011, 04:00 PM
Hi Corey,

 I am afraid we cannot do much to fix this as this is default behavior of the JavaScriptSerializer when it finds a circular object reference. You can check my blog post for further information as well as the grid troubleshooting help article.

Greetings,
Atanas Korchev
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
Tags
Grid
Asked by
dani
Top achievements
Rank 1
Answers by
Corey Gaudin
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or