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

ForeignKey view mode display

10 Answers 170 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Sid
Top achievements
Rank 1
Sid asked on 29 Mar 2012, 04:42 AM
I'm trying to use the ForeignKey column to display a dropdown list in a grid but can't figure out how to get the "name" data to display while in view mode on the grid.  When it is in edit mode it works great and I can get the data to post back just fine.  The ID field is showing and it has the right data, now I just need to get the user name to display instead.  I've attached the screen shots for both view and edit.
Here is the code for the razor view:
@(Html.Telerik().Grid<Journey>()
    .Name("grdJourney")
    .Columns(columns =>
                 {
                     columns.Bound(j => j.journey_desc)
                         .Title("Description");
                     columns.ForeignKey(j => j.UserId, new SelectList((IEnumerable<aspUser>)ViewData["UserList"],"UserId","FullName"))
                         .Title("Originator");
                        columns.Command(commands => commands.Edit()).Width(180).Title("Edit");
                 })
    .DataKeys(keys => keys.Add(j=>j.journey_id).RouteKey("journey_id"))
    .DataBinding(binding => binding.Ajax()
        .Select("AjaxJourneySelect","Journey")
        .Update("AjaxJourneyUpdate","Journey"))
    .Pageable(paging => paging.PageSize(10))
    .Sortable()
      )

I tried using a DisplayTemplate but to no avail.  So close, but no cigar!

Any ideas?
Thanks,
-Sid Meyers.

10 Answers, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 29 Mar 2012, 10:42 AM
Hi,

Did you take a look at this thread ? it give 2 examples of using ForeignKey.
0
Sid
Top achievements
Rank 1
answered on 29 Mar 2012, 01:34 PM
Everything is working except the "view" display is showing the ID and not the FULLNAME, if you look at the two attachments you'll see it.  The dropdown works perfectly in edit mode.  It has the correct name selected, if you change it, it posts back correctly.

So there is just something I'm missing in the display.  That's why I started down the displaytemplate route, but the examples here don't seem to have them.  It looks to me like I've got it right, but obviously I'm missing something.

Thanks,
-Sid.
0
Dadv
Top achievements
Rank 1
answered on 29 Mar 2012, 01:39 PM
It's why i tell you to look to the 2 examples in the other thread, to compare with your implementation.

The 2 sample was made by myself and was working as expected.

Edit : give us some of your controller to look in the ViewData value

Edit bis : if you use ForeignKey you should not need display/editor templates
0
Dadv
Top achievements
Rank 1
answered on 29 Mar 2012, 01:54 PM
I Just test with a new project and all work fine (version 2012.1.301.340)

 columns.ForeignKey(c => c.FKID,new SelectList(ViewBag.FKs,"Id","Text"));

 public ViewResult Index()
        {
            var Fks = new List<FK>();
            Fks.Add(new FK { Id = 1, Text ="Test" });
            Fks.Add(new FK { Id = 2, Text = "Test2" });


            ViewBag.FKs = Fks;
            return View();
        }

 public class FK
    {
        public int Id { get; set; }
        public string Text { get; set; }
    }
0
Sid
Top achievements
Rank 1
answered on 30 Mar 2012, 02:39 AM
Dadv,

Yes, I've written my own test as well and it works.  I'm not sure what I might be missing.  It's not that tough!  I think I'll just start from scratch and rewrite the page and see what happens.

Thanks for the suggestions.
-Sid.
0
Sid
Top achievements
Rank 1
answered on 30 Mar 2012, 03:20 AM
Knew it would be something easy.

The scripts files were not updated when I updated the telerik mvc extension!!!!!

Copied them in and worked like a charm.

-Sid.
0
kurt
Top achievements
Rank 1
answered on 03 Apr 2012, 03:34 PM
Sid,

I am running into the same issues.
Could you please let us see what the working code was.

thanks
--Kurt
0
Dadv
Top achievements
Rank 1
answered on 03 Apr 2012, 03:38 PM
Kurt, Like Sid try to look at the dll/scripts version (2012.1.X.X)
0
Sid
Top achievements
Rank 1
answered on 03 Apr 2012, 03:45 PM
Kurt,

Just manually copied the scripts from the "program files\telerik\{current version}\scripts\" into my project scripts directory.

HTH,
-Sid.
0
Domenico
Top achievements
Rank 1
answered on 28 Aug 2012, 05:53 PM
I'm loosing weeks looking for resolve the same problem.

How can I troubleshoot it?

In view mode all is working, but in edit mode, the editor template won't display. A textbox with the id is showed instead the combobox. What's wrong?

Thanks, Domenico.
Tags
Grid
Asked by
Sid
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Sid
Top achievements
Rank 1
kurt
Top achievements
Rank 1
Domenico
Top achievements
Rank 1
Share this question
or