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

[Solved] Ajax DataBinding question

0 Answers 89 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.
James
Top achievements
Rank 1
James asked on 09 Dec 2011, 09:35 PM
When I am using Ajax databinding, why can I not do something like this:

// dataResult in this case is a dynamic data-type, however resolves to an IEnumerable<>
return Json(dataResult, JsonRequestBehavior.AllowGet);


and instead have to do this:

return View(new GridModel<ProductViewModel>
{
    Data = dataResult; // still a dynamic type that resolves to an IEnumerable
}


I ask because it would be exceptionally beneficial to me to be able to use the first option.  Essentially, I have a page with several "widgets", each which make an Ajax request to the server to get the data they need to display.  In some cases this can be a JSON result that is evaluated in Javascript in my view, but in other cases (like this), I want to just bind that JSON result to my grid.  This way I can have a single method in my controller that takes a WidgetId to get the particular widget and call the GetData() method on that widget (which returns a dynamic).

Otherwise, if I have to use the second option, then I have to have some property on the widget class that determines if the resulting data is for a Telerik control, so I know to use the second option instead of the first option.  Which I can do, I would just rather not have to if I can avoid it.

So I guess my ultimate question is, is there a way to use the first option with Ajax databinding?  As it stands now, if I use it, I get a 404 response.  If I switch it to the second option, the grid populates easily.  Thanks.
Tags
Grid
Asked by
James
Top achievements
Rank 1
Share this question
or