How to bind the current data to grid when edit button is pressed

2 posts, 0 answers
  1. Victor
    Victor avatar
    23 posts
    Member since:
    Feb 2015

    Posted 12 May 2015 Link to this post

    I have a grid with data on it. When I want to edit the data, I need to press the edit button and a new edit form will open with the current data from the row.

    For the textboxes I use: 

    @Html.EditorFor(model => model.SubStatus)

    Now the issue is the dropDownList. Here is my code. the initial value is always blank?

    CSHTML code:

    @(Html.Kendo().DropDownListFor(m => m.SubType)
                    .Name("SubsType") 
                    .DataTextField("SubType1")
                    .DataValueField("SubType_ID") 
                    .DataSource(source =>
                    {
                        source.Custom()
                              .ServerFiltering(true)
                              .Type("aspnetmvc-ajax")
                              .Transport(transport =>
                              {
                                  transport.Read("GetType", "Welcome");
                              })
                              .Schema(schema =>
                              {
                                  schema.Data("Data")
                                        .Total("Total"); 
                              });
                    })
                )

     

    Razor code:

     public JsonResult GetSubType([DataSourceRequest] DataSourceRequest dropDownRequest)
            {
                IList<SubType> myViewModels = new List<SubType>();

                foreach (SubType subType in db.ExecuteStoredProcedure<SubType>("proc_getType", null))
                {
                    SubType subtype = new SubType()
                    {
                        SubType_ID = subType.SubType_ID,
                        SubType1 = subType.SubType1
                    };
                    myViewModels.Add(subtype);
                }
                return Json(myViewModels.ToDataSourceResult(dropDownRequest), JsonRequestBehavior.AllowGet);
            }

    Right now I get the list from the database. when the dropdownlist is pressed. but I want to set the initial value of the list to be the current value. How to do it?

  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3706 posts

    Posted 14 May 2015 Link to this post

    Hello Victor,

    The problem you are experiencing is related to the fact that the name is overridden by the Name method. When strongly-typed extension is used (For<T>) then Name is not required. You can find more details here.

    Regards,
    Georgi Krustev
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for ASP.NET MVC is VS 2017 Ready
Back to Top