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

How to add non-model data to Grid DataRoutevalues

1 Answer 82 Views
Grid
This is a migrated thread and some comments may be shown as answers.
BRiddle
Top achievements
Rank 1
BRiddle asked on 08 Jul 2014, 07:50 PM
I have a Grid with Server() datasource in an MVC5/EF6 Razor app with your 14.1.528.0 build.   I need to return a couple of model values plus a non-model Guid value from the ViewBag when a user selects a row.  I originally tried using the "onRowSelect" approach, but discovered that the dataItem() array was always null in the onRowSelect method when using a Server() datasource.   So I can get the first model field, the "Id" column, via the DataSource model reference.   But there was no way to obtain the selected row's 2nd model field in the "onRowSelect" method.   (BTW: Please add my vote for a feature other developers have requested: providing some way to access column values in the onRowSelect() when using a Server datasource).

I next tried using a custom Command button in each row.   It was easy to return a Url Action doing "DataRouteValues( route =>Route.Add()" to add the two model values for the selected row.  

But with this approach, I cannot find a syntax to return the non-model Guid value via Route.Add().   I've tried "Route.Add("@ViewBag.MyGuid",".   I've tried setting a JavaScript var equal to the ViewBag value in a page script block and doing "Route.Add(myJsGuidVar,", etc.    But the resulting error message makes it clear that Route.Add() will only accept a model reference.

I'm new to MVC and am assuming I'm making a simply mistake.   I'd rather not have to make a new ViewModel to add this column and take the time to redundantly populate this same Guid into every row.   What am I missing here?  Is there a way to add either a ViewBag property or a non-modal JavaScript Var to the DataRouteValues of the generated call?

Thanks!
-Bob

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 10 Jul 2014, 12:45 PM
Hello Bob,

Getting the client side model with the dataItem method of the Grid is not possible when using server-side binding because the cells are rendered directly from the server and there is no JavaScript equivalent of your models available on the client side.
Regarding the Route values that you mentioned in the second part of your message - I am not sure what exactly you have tried and what exactly you want the end result. You can create a hyperlink and append the ID of the row like shown here:

http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/faq#how-do-i-use-action-links

If this is not what you are searching for please share some code and point us where exactly you struggle.1

Kind Regards,
Petur Subev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
BRiddle
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or