Undefined value in Grid dropdown

1 Answer 83 Views
DropDownList Grid
nikky03
Top achievements
Rank 1
nikky03 asked on 21 Sep 2022, 10:16 PM | edited on 22 Sep 2022, 12:49 AM

Hello,

 

I have a kendo grid with the FundAge column with a dropdown list editor template. When I select the value from the dropdown and click update the value is showing as undefined. Can someone help with this?

///Editor template

@model Models.FedAge

@(Html.Kendo().DropDownListFor(x => x)
    .DataValueField("FedId")
    .DataTextField("FedDesc")
    .BindTo((System.Collections.IEnumerable)ViewData["FedAge"]))

 

//////// Grid column

 

 @(Html.Kendo().Grid<AgencyInformation>()
    .Name("AgencyInformationGrid")
    .Columns(columns =>
    {
        columns.Bound(p => p.FundAge).ClientTemplate("#=FundAge.FedDesc#").Sortable(false).Width(175).HtmlAttributes(new { @class = "FundAgeClass" });        
    }) 

.ToolBar(toolbar => toolbar.Create())
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:500px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .AutoSync(false)
        .Batch(false)
        .PageSize(20)
        .ServerOperation(false)
        .Events(events => events.Error("errorHandler"))
        .Events(events => events.RequestEnd("onAgeInfoRequestEnd"))
        .Model(model => {
            model.Id(p => p.AgeInfoId);
            model.Field(p => p.AgeInfoId).Editable(false);
            model.Field(p => p.FedAge.FedAgeDesc).Editable(false).DefaultValue(ViewData["FedAge"]);
        })
        .Create(update => update.Action("AddAgeInfo", "Cove").Type(HttpVerbs.Post))
        .Read(read => read.Action("GetAgeInfo", "Cove").Type(HttpVerbs.Get))
        .Update(update => update.Action("EditAgeInfo", "Cove").Type(HttpVerbs.Post))
        .Destroy(update => update.Action("DeleteAgeInfo", "Cove").Type(HttpVerbs.Post))
    )

 

 

//////Entity

 

public class AgeInfo
    {
        public string AgenfoId { get; set; }

        [UIHint("FedlAgeEditor")]
        [Required(ErrorMessage = "Required")]        
        public string FundAge{ get; set; }


        public FedAge FedAge{ get; set; }
    }


    public class FedAge
    {
        public int FedAgeId { get; set; }

        public string FedAgeDesc { get; set; }
    }
}

 

///controller

 [HttpGet]
        public IActionResult AgeInfo()
        {
            //if (coveDetails!= null && coveDetails.AgeInfo!= null)
            //{
            //    return View("AgeInfo", coveDetails.AgeInfo);
            //}
            ViewData["FedAge"] = lookupsDetails.FedAge;
            ViewBag.FedAge= lookupsDetails.FedAge;
            return View();
        }   

 

Can some one please help??

1 Answer, 1 is accepted

Sort by
0
Mihaela
Telerik team
answered on 26 Sep 2022, 12:18 PM

Hello Nikitha,

I examined the provided code snippets and I would recommend the following:

  • The Grid column is bound to the string property "FundAge", but the DropDownList editor is bound to the complex property "FedAge". When adding a new record, the selected DropDownList value will be submitted as "FundAge", so you need to update manually the "FedAge" property server-side. Otherwise, when the new record is received from the server, the "FedAge" property will be empty.  
  • The property that holds the description of the "FedAge" Model is "FedAgeDesc". Please update it in the ClientTemplate() of the Grid column - .ClientTemplate("#=FedAge.FedAgeDesc#").

    In addition, I have created a runnable sample, where the Grid column is bound to the complex property "FedAge", and the column is successfully updated through the custom DropDownList editor. You can review it attached. Hopefully, it will help you to fix the issue at your end.

     

    Regards, Mihaela Progress Telerik

    Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

    nikky03
    Top achievements
    Rank 1
    commented on 26 Sep 2022, 09:31 PM | edited

    Hello Mihaela,

     

    Thank you for your response. I made some changes and now it is working fine.

     

    Thanks for your help

    Tags
    DropDownList Grid
    Asked by
    nikky03
    Top achievements
    Rank 1
    Answers by
    Mihaela
    Telerik team
    Share this question
    or