Assume we have these two tables, binded by foreign key CAT_ID:
Category[CAT_ID,CAT_NAME]
cat_id = 1, cat_name= Classical
cat_id = 2, cat_name = Jazz
…
MusicAlbums[ALBUM_ID, ALBUM_NAME, CAT_ID]
album_id = 1, album_name = Wagner – Parsifal, cat_id=1
album_id = 2, album_name = “Davis Miles – Kind of Blue, cat_id = 2
How can I display on MVC View instead of CAT_ID its value(that is : CAT_NAME) ?
like this:
———
Music
1 | Wagner – Parsifal | Classical
2 | Davis Miles – Kind of Blue | Jazz
———
Thank you
You want the Foreign Key feature (Its marked as new so may not have been available when you first looked):
http://demos.telerik.com/aspnet-mvc/grid/foreignkeycolumn
(View code (from their site, slightly cleaned up))
ViewData is set in the initial controller action:
Their ‘AjaxEdit’ controller action does some funky stuff with explicitly listed foreign key ids in the parameters. But as my object exposed the FK fields I found in worked as expected without the need for any tricky business..
Bonus points to anyone who can provide an example of filtering/sorting on the displayed value on these columns as these features apply themselves to the underlying ‘id’ value rather than the displayed string (annoying!)