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

Object properties / methods undefined with MVC

1 Answer 108 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Todd Fulmino
Top achievements
Rank 1
Todd Fulmino asked on 25 Feb 2013, 04:47 PM

We are creating an MVC 4 application using the Kendo.Mvc helper assembly. The code is working well; however, we appear to be missing something when we try to obtain a reference to a kendo control.

Example:
Our application has an ActionLink on a toolbar. When the user clicks on the ActionLink, we call into a JS function to validate if the displayed grid has a row selected. Within the function we attempt to obtain a reference to the grid and get the selected row. Unfortunately, the select() function throws an error ("Value is undefined").

I have included the code below. Most of our logic will be based on controls having the ability to communicate with each other from events, etc. Are we able to receive  the functionality using the MVC assembly, or are we only able to use the API when code in JS?

Any comments or assistance would be much appreciated.

Thanks,
Todd

@(Html.Kendo().Grid(Model.Transaction)
.Name("grid")
.Columns(columns => {
    columns.Bound(o => o.EntityId)
        .Hidden().Visible(false);
    columns.Bound(o => o.EntityName)
        .Sortable(true)
        .Title("Entity Name")
        .ClientTemplate(@Html.ActionLink("#=EntityName#", "Details", "Entity", new { id = "entityId" }, null).ToHtmlString().Replace("entityId", "#=EntityId#"));
    columns.Bound(o => o.TransactionType);
    columns.Bound(o => o.Name)
       .ClientTemplate(@Html.ActionLink("#=Name#", "Details", "Engagement", new { id = "engId" }, null).ToHtmlString().Replace("engId", "#=ID#"));
    columns.Bound(o => o.TransactionStatus);
    columns.Bound(o => o.Initiator);
    columns.Bound(o => o.Reason);  
      
})
.Pageable(p => p.PageSizes(true))
.Filterable(filterable => filterable
    .Extra(false)
    .Operators(operators => operators
        .ForString(str => str.Clear()
            .StartsWith("Starts with")
            .IsEqualTo("Is equal to")
            .IsNotEqualTo("Is not equal to")
        ))
    )
.Navigatable()
.Resizable(resize => resize.Columns(true))
.Selectable()
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(p => p.ID))
    .Read(r => r.Action("Search", "Transaction")))
)
getSelectedRowId: function (gridId) {
            var grid = jQuery(gridId).kendoGrid().data("kendoGrid");
            var row = grid.select();
 
            if (row.length > 0)
                return grid.dataItem(row).id;
            else
                return null;
        }

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 26 Feb 2013, 12:29 PM
Hello Todd ,

 
Here is how you should access existing instance of Grid widget:
http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/overview#accessing-an-existing-grid-instance

var grid = jQuery(gridId).kendoGrid().data("kendoGrid");
The line above creates new grid widget over existing one and returns reference to it.

Regards,
Nikolay Rusev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Todd Fulmino
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or