1
votes

I have a Telerik MVC Grid with a custom editable popup template

.Editable(editable => editable
    .Mode(GridEditMode.PopUp)
    .Window(w => w.Width(600))
    .TemplateName("Inspection")
 )

The template is based on a model, and contains two drop down lists

    @(Html.Kendo().DropDownListFor(model => model.InspectionStatus)
    .BindTo(new List<SelectListItem>()
    {
        new SelectListItem() { Text = "Fail", Value = "0" },
        new SelectListItem() { Text = "Pass", Value = "1" }
    })
    )

and

    @(Html.Kendo().DropDownListFor(model => model.CloseoutStatusID)
    .DataValueField("LookUpID")
    .DataTextField("LookUpText")
    .DataSource(source => {
        source.Read(read => { read.Action("Get", "LookUp", new { LookUp = "CloseOutStatus" }); });
    })
    )

I need to set the default values for both fields... Currently they both come back as 0 regardless of what I have done.

So far I've:

  • Tried setting the default value attribute
  • Set the values in the model's constructor
  • Set the .Value() to what the default should be.

Everything else is working correctly... I can select a bound item and it returns the correct value. I can edit an existing item and it shows the proper data in the template. I can saved edited data and it returns the correct value.

Any reliable documentation would be greatly appreciated.

1
Try adding the .Name() property to both dropdowns. I believe the name needs to be the same as the model property you are using it for. So .Name("InspectionStatus") and .Name("CloseoutStatusID").ShawnOrr
Since I'm using DropDownListFor, it is already rendering with the name. I just tried adding the name property to the drop downs it doesn't change the behavior.Patrick

1 Answers

1
votes

Received the answer on the telerik forums.

The telerik grid create action in the toolbar uses the model information in the data source.

by adding the fields to the model and setting the default value there I was able to get the desired behavior.

    .Model(model => {
        model.Id(Inspection => Inspection.DEPInspectionsID);
        model.Field(Inspection => Inspection.CloseoutStatusID).DefaultValue(2);
        model.Field(Inspection => Inspection.InspectionStatus).DefaultValue(1);
        })