Q:

Getting error to find length of grid in MVC using javascript

I was getting length of Grid row successfully using java script till now but today its giving error-
Cannot read property 'length' of undefined
 var totalRows = document.getElementById("gridposition").rows.length;

<div id="gridposition" style="width: 100%;">
    @{

        @grid1.GetHtml(mode: WebGridPagerModes.All,
                tableStyle: "table",
                headerStyle: "gridHead",
                footerStyle: "foot",
                rowStyle: "gridRow",
                alternatingRowStyle: "gridAltRow",
                htmlAttributes: new { id = "positionGrid" },
                fillEmptyRows: false,
                columns: grid1.Columns(
                           grid1.Column(format: @<text><input type="checkbox" name="ids" class="myCheckbox" value="@item.empId"></text>, header: "Select"),
                           grid1.Column("empId", header: "Id"),
                           grid1.Column("Name", header: "Name"),
                           grid1.Column("Age", header: "Age"),
                           grid1.Column(header: "Edit", format: @<text><a href="javascript:void(0)" onclick="editEmp(@item.empId)">Edit</a></text>),
                           grid1.Column("", header: "Edit", format: @<text>@Html.ActionLink("Edit", "EditEmployee", "BootStrap", new { id = item.empId }, new { target = "_blank", id = "editColumn" })</text>)
))
        <input type="submit" value="Delete" id="btnDelete" />
    }
</div>

A:

Looking at your web grid properties you should instead be doing 
var totalRows = document.getElementById("positionGrid").rows.length;

As you've set the Id of the grid to be "positionGrid"
htmlAttributes: new { id = "positionGrid" },
                             ^^^^^^^^^^ 

