0
votes

I have an mvc editor template (named ExpenseTypeEdit) defined like this:

@model ExpenseType
@(Html.Kendo().DropDownListFor(et => et.ExpenseTypeId)
    .OptionLabel("--Please Select--")
    .DataTextField("Description")
    .DataValueField("ExpenseTypeId")
    .DataSource(datasource => datasource
        .Read("GetExpenseTypeList", "Lookup", new { area = "" })
    )
    .HtmlAttributes(new { width = "98%" })   
)

I have a kendo grid that looks something like this:

@(Html.Kendo().Grid<ExpenseViewModel>()
    .Name("ExpenseGrid")
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .Columns(columns =>
    {
        columns.Bound(e => e.ExpenseType)
            .EditorTemplateName("ExpenseTypeEdit");         
        columns.Command(command =>
            {               
                command.Custom("SaveExpense").Click("SaveExpense_click").Text("Save");              
            }
        );
    })
    .DataSource(datasource => datasource.Ajax()
        .ServerOperation(false)
        .Model(model =>
        {
            model.Id(i => i.ExpenseId);
            model.Field(f => f.ExpenseType)
                .DefaultValue(new Solutions.Business.Entities.PrimitiveObjects.ExpenseType { ExpenseTypeId = 0, Description = "" });
        })          
    )
)

The function SaveExpense_click looks like this:

function SaveExpense_click(e) {
    var item = this.dataItem($(e.currentTarget).closest("tr"));     

    /*
        Variable 'item' looks like like:

        {
            ExpenseType: {
                ExpenseTypeId: 4,
                Description: ""
            }           
        }   
    */  
    //debugger;
};

The ExpenseTypeId is present but not the description. Why is item not picking up the Description from the drop down and what do I need to do to get it passed in?

1
is your dropdown contains description? - Rudresha Parameshappa

1 Answers

0
votes

You can't get the Description of a DDL server side, you can only get the value. You can either get the value then retrieve the text from the DB or you can use the combo box control and then you will be able to get both value and text.

Just noticed your tryign to get it client side, if thats the case.

$("#ExpenseTypeId").text() should work, as per your example item.text() might work