0x800a1391 - JavaScript runtime error: 'myGrid' is undefined

Jun 15, 2013 at 4:04 PM
Edited Jun 15, 2013 at 4:05 PM
Hi,

I just started using this component and ran into this issue.

Here's the .cshtml:
<script src="@Url.Content("~/Scripts/jquery-1.10.1.min.js")" type="text/javascript"> </script>
<link href="@Url.Content("~/Content/Gridmvc.css")" rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/gridmvc.min.js")" type="text/javascript"> </script>

<script type="text/javascript">

    myGrid.onRowSelect.onRowSelect(function (row) {
        alert(1);
    });

</script>

<div id="userslist">
    @Html.Grid(Model, GridRenderOptions.Create("myGrid")).Columns(columns =>
           {
               columns.Add(x => x.UserName).Titled("User").SetWidth(110).Filterable(true);
               columns.Add().RenderValueAs(model => "Item " + model.UserId);
           }).WithPaging(20)

</div>
Coordinator
Jun 16, 2013 at 3:56 PM
Hi,

You need to place script block after grid or use DOM ready event:
<script type="text/javascript">
$(function(){
    myGrid.onRowSelect.onRowSelect(function (row) {
        alert(1);
    });
});
</script>