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

[Solved] Issue Loading Grid In a Partial View from another Partial View

3 Answers 117 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.
Forest
Top achievements
Rank 1
Forest asked on 04 Jul 2011, 06:41 PM
See below... 

3 Answers, 1 is accepted

Sort by
0
Forest
Top achievements
Rank 1
answered on 04 Jul 2011, 07:57 PM
Scratch the initial question.  I found an article on your site outlining how to load the grid via jQuery and that has gotten me much closer. Basically I have replaced the Html.Partial with a <div id="visitGrid"></div> and am loading the div in this fashion:
<script type="text/javascript">
    $(document).ready(function () {
       // Ommitted...
        loadPartialView();
    });
 
    function loadPartialView() {
        $('#visitGrid').load('@Url.Action("_Visits", "Visitor")');
    }

Here's the controller action that I have in the ajax.select in the Grid itself:
public ActionResult _Visits()
{
   return PartialView("_Visits", (List<VisitViewModel>)Session["Visits"]);
}

The only issue here is whenever I do anything (paging, sorting, etc.), I keep getting a Javascript alert:

Error! The requested URL did not return Json!

I have seen this error on a thread earlier, but supposedly it was fixed in a new release.

Here's the script files at the bottom of the page in the scripts section:
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.5.1.js" type="text/javascript"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.13/jquery-ui.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.maskedinput-1.3.js" type="text/javascript"></script>

<script src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>

<script type="text/javascript" src="/Scripts/2011.1.315/telerik.common.min.js"></script>
<script type="text/javascript" src="/Scripts/2011.1.315/telerik.grid.min.js"></script>
<script type="text/javascript" src="/Scripts/2011.1.315/telerik.grid.filtering.min.js"></script>

Also: I have tried decorating the Action method with [GridAction], though that did not change.  It's identifical to what's here:

http://www.telerik.com/help/aspnet-mvc/using-with-partial-views-loaded-via-ajax.html

The only difference is I'm not clicking a hyperlink to load up the Grid.  

Please assist.  Thank you.
0
Forest
Top achievements
Rank 1
answered on 04 Jul 2011, 10:01 PM
I fixed this issue.  Had to add another action result that returns a GridModel decorated with a GridAction attribute.  In the example I posted from your documentation, I wrongfully assumed the Orders passed into the Ajax.Select method was a typo as I didn't see that ActionResult in the documentation.

It may be helpful to update that documentation with something like the following for completeness.

Anyway, awesome Grid and I'm happy this is all firing properly now! 

My recommendation to your documentation for Step 6:
[GridAction]
public ActionResult Orders()
{
    return View(new GridModel(NorthwindDataContext.Orders));
}
0
Max
Top achievements
Rank 1
answered on 05 Jan 2012, 09:59 PM
wow I had EXACTLY the same issue.
They havent changed the help file yet but I am glad I found your thread here :)
Thanks

Tags
Grid
Asked by
Forest
Top achievements
Rank 1
Answers by
Forest
Top achievements
Rank 1
Max
Top achievements
Rank 1
Share this question
or