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

[Solved] Telerik Editor in grid show no data when editing

1 Answer 146 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.
Daniel
Top achievements
Rank 1
Daniel asked on 10 Jan 2011, 03:49 PM
I have a Telerik Editor in a Telerik Grid with Ajax Binding. The grid contais a TelerikDropdown too, but it's work fine.

When I press the Edit button, the Telerik Editor show no data.

My view model is:

public class DiagnosticViewModel
    {
        [ScaffoldColumn(false)]
        public int Id
        {
            get;
            set;
        }
        // Tipo de diagnostico
        [Required(ErrorMessage = "Campo obligatorio")]
        [DisplayName("Tipo de Diagnostico")]
        [UIHint("DiagnoticType")]
        public string TipoDiagnostico
        {
            get;
            set;
        }
 
        [Required(ErrorMessage = "Campo obligatorio")]
        [DisplayName("Nombre")]
        [DataType(DataType.Text)]
        public string Nombre
        {
            get;
            set;
        }
 
        [Required(ErrorMessage="Campo obligatorio")]
        [DisplayName("Fecha de creación")]
        [DataType(DataType.Date)]
        [ScaffoldColumn(false)]
        public DateTime FechaCreacion
        {
            get;
            set;
        }
 
        [Required(ErrorMessage = "Campo obligatorio")]
        [DisplayName("Condición")]
        [UIHint("Editor")]
        public string Condicion
        {
            get;
            set;
        }
 
        [Required(ErrorMessage = "Campo obligatorio")]
        [DisplayName("Descripción")]
        [DataType(DataType.MultilineText)]
        public string Descripcion
        {
            get;
            set;
        }
    }

The template for Editor is:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
 
<%= Html.Telerik().Editor()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .Localizable("es-ES")
        .Value(Model)
        .Tools(tools => tools
            .Clear()
            .Bold().Italic().Underline()
            .Separator()
            .FontColor()
            .CreateLink().Unlink()
        )
%>

The template for Dropdown is (works fine):

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
 
<%= Html.Telerik().DropDownList()
        .Name("TipoDiagnostico")
            .BindTo(new SelectList((IEnumerable)ViewData["DiagnoticType"], "id", "descripcion"))
%>

The grid is (I use T4MVC):

<%= Html.Telerik().Grid<PHDWeb.ViewModels.DiagnosticViewModel>()
        .Name("DiagnosticGrid")
        .Localizable("es-ES")
        .DataKeys(keys => keys.Add(p => p.Id).RouteKey("Id"))
        .ToolBar(
                 commands => commands.Insert()
                 .ButtonType(GridButtonType.ImageAndText)
                 .ImageHtmlAttributes(new { style = "margin-left:0" })
                )
        .DataBinding(dataBinding =>
        {
            dataBinding.Ajax()
                .Select(MVC.PortalSercotec.Diagnostic._SelectDiagnostic().GetRouteValueDictionary())
                .Insert(MVC.PortalSercotec.Diagnostic._InsertDiagnostic().GetRouteValueDictionary())
                .Update(MVC.PortalSercotec.Diagnostic._UpdateDiagnostic().GetRouteValueDictionary())
                .Delete(MVC.PortalSercotec.Diagnostic._DeleteDiagnostic().GetRouteValueDictionary());
        })
        .Columns(columns =>
        {
            columns.Bound(p => p.Nombre).Width(130).Title("Nombre");
            columns.Bound(p => p.Descripcion).Width(130).Title("Descripción");
            columns.Bound(p => p.FechaCreacion).Width(130).Title("Fecha de creación");
            columns.Bound(p => p.Condicion).Width(130).Width(130).Title("Condición").Encoded(false);
            columns.Bound(p => p.TipoDiagnostico).Width(130).Title("Tipo Diagnóstico");
            columns.Command(commands =>
            {
                commands.Edit().ButtonType(GridButtonType.ImageAndText);
                commands.Delete().ButtonType(GridButtonType.ImageAndText);
            }).Width(180).Title("Acciones");
        })
        .Editable(editing => editing.Mode(GridEditMode.PopUp))
            .ClientEvents(events =>
                {
                    events.OnEdit("onEditDiagnostic");
                }
                )
        .Pageable()
        .Sortable()
    %>

My Controller is:

[GridAction]
        public virtual ActionResult _SelectDiagnostic()
        {
            ViewData["DiagnoticType"] = _diagnosticTypeRepository.GetAll();
 
            return View(new GridModel<DiagnosticViewModel>
            {
                Data = _diagnosticRepository.GetAllViewModel()
            });     
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        [CultureAwareAction]
        [GridAction]
        public virtual ActionResult _InsertDiagnostic(DiagnosticViewModel diagnosticToInsert)
        {
            if (TryUpdateModel(diagnosticToInsert))
            {
                // Decodear el HTML de condición
                diagnosticToInsert.Condicion = HttpUtility.HtmlDecode(diagnosticToInsert.Condicion);
                diagnosticToInsert.FechaCreacion = DateTime.Now;
                _diagnosticRepository.Insert(diagnosticToInsert);
            }
 
            ViewData["DiagnoticType"] = _diagnosticTypeRepository.GetAll();
 
            //Rebind the grid
            return View(new GridModel<DiagnosticViewModel>
            {
                Data = _diagnosticRepository.GetAllViewModel()
            });
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        [CultureAwareAction]
        [GridAction]
        public virtual ActionResult _UpdateDiagnostic(int id)
        {
            DiagnosticViewModel diagnosticToUpdate = _diagnosticRepository.GetViewModel(id);
 
            if (TryUpdateModel(diagnosticToUpdate))
            {
                // Decodear el HTML de condición
                diagnosticToUpdate.Condicion = HttpUtility.HtmlDecode(diagnosticToUpdate.Condicion);
                _diagnosticRepository.Update(diagnosticToUpdate);
            }
 
            ViewData["DiagnoticType"] = _diagnosticTypeRepository.GetAll();
 
            //Rebind the grid
            return View(new GridModel<DiagnosticViewModel>
            {
                Data = _diagnosticRepository.GetAllViewModel()
            });
        }
 
        [AcceptVerbs(HttpVerbs.Post)]
        [GridAction]
        public virtual ActionResult _DeleteDiagnostic(int id)
        {
            DiagnosticViewModel diagnosticToDelete = _diagnosticRepository.GetViewModel(id);
 
            if (diagnosticToDelete != null)
            {
                _diagnosticRepository.Delete(diagnosticToDelete.Id);
            }
 
            ViewData["DiagnoticType"] = _diagnosticTypeRepository.GetAll();
 
            //Rebind the grid
            return View(new GridModel<DiagnosticViewModel>
            {
                Data = _diagnosticRepository.GetAllViewModel()
            });
        }

I attach an image. My Telerik version is 2010.3.1129.235.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Shiva
Top achievements
Rank 1
answered on 08 Apr 2011, 01:45 PM
Hi Telerik Team,

Am also having exactly the same issue. But I am not sure how Demo is working fine. Please could you explain how to load editor in Grid. 

Thanks,
Siva
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Shiva
Top achievements
Rank 1
Share this question
or