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

[Solved] Grid do not render ForeignKey Columns

2 Answers 154 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Alexander
Top achievements
Rank 1
Alexander asked on 16 May 2012, 10:51 PM
My View:

@(Html.Telerik().Grid<Entities.Noticia>()
        .Name("Grid")
        .DataKeys(keys =>
        {
            keys.Add(p => p.Id);
        })
        .ToolBar(commands => commands.Insert().ButtonType(tipoBotao).ImageHtmlAttributes(new {style="margin-left:0"}))
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
                .Select("_AjaxIndex", "Noticia")
                .Insert("_AjaxInserir", "Noticia")
                .Update("_AjaxAlterar", "Noticia")
                .Delete("_AjaxExcluir", "Noticia");
        })
        .Columns(columns =>
        {
            columns.Bound(p => p.Titulo).Width(100).Title("Titulo");
            columns.Bound(p => p.Texto).Title("Texto").Encoded(false);
            columns.ForeignKey(p => p.Autor.Id, (IEnumerable<Autor>)ViewData["Autores"], "Id", "Nome").Title("Autor");
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(tipoBotao);
                commands.Delete().ButtonType(tipoBotao);
            }).Title("Ações").Width(100);
        })
        .Editable(editing => editing.Mode(tipoEdicao))
        .Pageable()
        .Sortable()      
)


My Entities:

public class Noticia
    { 
        [ScaffoldColumn(false)]
        public virtual int Id { get; set; }
 
        public virtual String Titulo { get; set; }
 
        public virtual String Texto { get; set; }
 
        public virtual Autor Autor { get; set; }
 
    }
 
  public class Autor
    {
        [ScaffoldColumn(false)]
        public virtual int Id { get; set; }
 
        public virtual String Nome { get; set; }
 
        public virtual DateTime DataNascimento { get; set; }
 
    }


My Controller:

[GridAction]
        public ActionResult _AjaxIndex()
        {
            PopulaAutores();
            return View(new GridModel(NoticiaManager.GetAll()));
        }
 
private void PopulaAutores()
        {
            ISession session = NHibernetHelper.GetSession();
            var _autores = session.Query<Autor>().ToList();
            ViewData["Autores"] =_autores
        }

Jason Reurned:

{"data":[{"Id":2,"Titulo":"titulo 2","Texto":"texto 2 - ipsum 666","Autor":{"Id":4,"Nome":"tsasda basf","DataNascimento":"\/Date(1345690800000)\/"}},{"Id":3,"Titulo":"teste","Texto":"lalalala 5","Autor":{"Id":1,"Nome":"Alexander","DataNascimento":"\/Date(380080800000)\/"}},{"Id":4,"Titulo":"teste 2 ","Texto":"hehehehehehe","Autor":{"Id":1,"Nome":"Alexander","DataNascimento":"\/Date(380080800000)\/"}},{"Id":5,"Titulo":"teste","Texto":"lalalala 53","Autor":null},{"Id":6,"Titulo":"teste michel","Texto":"dioablo 3 rlz!!!!!","Autor":null},{"Id":7,"Titulo":"dfgsdfgsdafsdfas","Texto":"33333","Autor":{"Id":4,"Nome":"tsasda basf","DataNascimento":"\/Date(1345690800000)\/"}},{"Id":9,"Titulo":"sdfagsdgasgasdgas","Texto":"33333333","Autor":{"Id":4,"Nome":"tsasda basf","DataNascimento":"\/Date(1345690800000)\/"}},{"Id":10,"Titulo":"teste","Texto":"juca","Autor":{"Id":1,"Nome":"Alexander","DataNascimento":"\/Date(380080800000)\/"}}],"total":8}


The View only render the columns:
  • Titulo  (columns.Bound )
  • Texto  (columns.Bound ) 
  • Ações (columns.Command )





2 Answers, 1 is accepted

Sort by
0
Muhamad Tassadaque Zia
Top achievements
Rank 1
answered on 28 May 2012, 12:51 PM
Please make sure that you have included the GridForeignKey editor template. If you are using inform/popup mode make sure you have added  [UIHint("GridForeignKey")] attribute to your model property 


0
JORGE
Top achievements
Rank 1
answered on 01 Oct 2012, 11:28 AM
Alexander

Do you speak portuguese?
Você conseguiu resolver o problema?. Também estou com o mesmo problema.

Grato.
Tags
General Discussions
Asked by
Alexander
Top achievements
Rank 1
Answers by
Muhamad Tassadaque Zia
Top achievements
Rank 1
JORGE
Top achievements
Rank 1
Share this question
or