3

I'm new to all this, and did research this quite a bit, and apparently don't "get it". I'm using C#/.NET4.5 MVC4.

I have a drop down list I populated, and when I change the drop down value, I want to trigger an event.. change event I believe (to redirect to a new page with the value of the drop down selection)

Nothing happens (event not triggered).
I tried using the .Events syntax as part of the Kendo code, but I get an error (error CS1977: Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type)

I'm afraid I don't understand the process flow and how to bind the event to the action, in spite of reading a dozen or more posts about this. Thanks in advance for your help.

Here is what I got in my View (index.cshtml)

@model IEnumerable<cfcccDb.Models.matrix>

<form method="post">

@(Html.Kendo().DropDownList()

    .Name("scorematrix")
    .DataTextField("Text")
    .DataValueField("Value")
    .Value(ViewBag.SelectedMatrix)
    .HtmlAttributes(new { style = "width:200px;" })
    .BindTo(@matrixlist)
    )

</form>

<script>

$("#scorematrix").kendoDropDownList({

    change: function (e) {
        var value = this.value();
        alert("value = " + value);
    }

})

</script>

1
  • FYI, I have the closing paren not show in the ddl code, and I have the ";" after the close paren even though not show here, so that is not the problem Jan 24, 2014 at 16:44

1 Answer 1

4

With the MVC wrappers, you should do this to bind the change event:

@(Html.Kendo().DropDownList()
    .Name("scorematrix")
    .DataTextField("Text")
    .DataValueField("Value")
    .Value(ViewBag.SelectedMatrix)
    .HtmlAttributes(new { style = "width:200px;" })
    .BindTo(@matrixlist)
    .Events(e => e.Change("dropdownlist_change")))

<script>
    function dropdownlist_change() {
        //Handle the change event
    }
</script>

If you want to bind the change event in JS, you can do this:

$("#scorematrix").data("kendoDropDownList").bind("change", function (e) {
    //Handle the change event
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.