This question is locked. New answers and comments are not allowed.
While making my first attempt at setting up an AjaxBinding, the grid shows an alert box that says "Error! The requested URL returned 500 - Internal Server Error". How can I see the exception details that caused the error?
6 Answers, 1 is accepted
0
flipdoubt
Top achievements
Rank 1
answered on 29 Apr 2010, 10:57 PM
I found I can see the error using Firebug's Script console. The data-context is being disposed, even though I am passing in the creation of the GridModel in a Func like so:
I thought the Func would avoid all the disposal issues because it is called within the using block, where the NewSession() call creates a new data-context inside of _CeoDb. Any ideas?
| [GridAction] |
| public virtual ActionResult ListAjaxBinding() |
| { |
| try |
| { |
| Func<IQueryable<DocumentResult>, ActionResult> func = results => View(new GridModel(results)); |
| return _UserService.QueryDocumentResults(func); |
| } |
| catch (Exception e) |
| { |
| _LogService.LogException(e); |
| return View(); |
| } |
| } |
| public TResult QueryDocumentResults<TResult>(Guid userId, Func<IQueryable<DocumentResult>, TResult> func) |
| where TResult : class |
| { |
| using (_CeoDb.NewSession()) |
| { |
| var result = _CeoDb.Documents.Where(d => d.UserId == userId) |
| .Select(d => |
| new DocumentResult |
| { |
| DocumentId = d.DocumentID, |
| Description = d.DocComment, |
| DocumentDate = d.DocumentDate, |
| LastUpdatedDate = d.DocumentFiles.Where(df => df.Version > 0).Max(df => df.FileDate) |
| }); |
| return func(result); |
| } |
| } |
I thought the Func would avoid all the disposal issues because it is called within the using block, where the NewSession() call creates a new data-context inside of _CeoDb. Any ideas?
0
Hi flipdoubt,
I think the lazy initialization of the IQueryable is the problem. The context is still disposed immediately after the the Func is executed. Later when the grid tries to enumerate the IQueryable the latter throws that exception. As a workaround I can suggest to dispose you context in the Despose method of your controller (you have to override it first).
All the best,
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.
I think the lazy initialization of the IQueryable is the problem. The context is still disposed immediately after the the Func is executed. Later when the grid tries to enumerate the IQueryable the latter throws that exception. As a workaround I can suggest to dispose you context in the Despose method of your controller (you have to override it first).
All the best,
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.
0
flipdoubt
Top achievements
Rank 1
answered on 30 Apr 2010, 04:12 PM
Hi Atanas. How can the grid try to enumerate the IQueryable "later" when I call View(new GridModel()) within the Func? Does the GridModel constructor do something funky with the Page lifecycle such that it executes later? I thought getting rid of the Page lifecycle was part of the point of MVC. Since this is an Ajax request where the page is not really needed, I am surprised by your suggestion to dispose of the DataContext in the Controller's Dispose method. The sample code I posted is really a simplified example: the data-access code actually lives in the data-access layer defined in a separate project, which is why I pass the Func into the GetDocumentResults method. Can you give me some idea as to how/when Telerik code runs outside of my using statement?
Thanks.
Thanks.
0
flipdoubt
Top achievements
Rank 1
answered on 30 Apr 2010, 06:47 PM
I guess what I'm asking is as follows: Doesn't all the enumeration happen in the line that reads "View(new GridModel(results));" called by func? Since func is called inside the using clause, I think I am good. What does the grid do after the using clause?
0
Accepted
Hello flipdoubt,
This is all explained in the ajax binding help topic. Check the info about the GridActionAttribute.
To answer your question - the enumeration does not happen in the new GridModel() clause since there is not enough info to perform all the required operations at that point. The GridActionAttribute calls the data processing and returns json behind the scenes. If you don't need this you can always use custom binding.
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.
This is all explained in the ajax binding help topic. Check the info about the GridActionAttribute.
To answer your question - the enumeration does not happen in the new GridModel() clause since there is not enough info to perform all the required operations at that point. The GridActionAttribute calls the data processing and returns json behind the scenes. If you don't need this you can always use custom binding.
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.
0
flipdoubt
Top achievements
Rank 1
answered on 30 Apr 2010, 10:06 PM
Thanks. I concluded on my own that I had to go with CustomBinding to support the separated data-layer architecture. If there is enough info present to do the custom binding, then I contend there should be enough info present to do the non-custom binding, but I am satisfied at this point.