0

Hi I manage to make my problem on dropdownlist work but still i encountered another issue. this is my new code;

@foreach (var props in mymodel.GetType().GetProperties().ToList())
        {
            <div class="editor-line">
                <label>@props.Name </label>
                @(Html.Kendo().DropDownList()
                    .Name("ddl1_" + @props.Name)
                    .OptionLabel("Select")
                    .DataTextField("Text")
                    .DataValueField("Value")
                    .AutoBind(false)                    
                    .Events(e => e.Change("onSelect"))
                    .HtmlAttributes(new { style = "width: 25%" })
                )
            </div>
        }

and here's how i populate them, sorry for the bad practice.

@foreach (var props in mymodel.GetType().GetProperties().ToList())
            {
                <text>
                    var ddl = $('#ddl1_' + "@props.Name").data("kendoDropDownList");
                    ddl.setDataSource(ddlSource);
                </text>
            }

now my problem is the .Events(e => e.Change("onSelect")) code is not working, it makes may page fail to load because it cannot find the onSelect function.

here is the code in javsacript

function onSelect(e) {
        debugger;
        if (e.item) {
            var dataItem = this.dataItem(e.item);
            var elementId = e.sender.element[0].id
            console.log(elementId);
            console.log("event :: select (" + dataItem.Text + " : " + dataItem.Value + ")");
        } else {
            console.log("event :: select");
        }
    }
jon
  • 23
  • 7
  • See if this can help: https://stackoverflow.com/questions/5015830/get-the-value-of-displayname-attribute – Kalp Jul 27 '17 at 07:14
  • So whats preventing you to do so in your controller? – SᴇM Jul 27 '17 at 08:13
  • I did this on the Controller side. List result = GetEntityModel(4) .GetProperties() .Where( p => p.GetCustomAttributes(typeof(CanBulkUpdateAttribute), true) .Where(ca => ((CanBulkUpdateAttribute)ca).CanBulkUpdate) .Any() ) .ToList(); – jon Jul 27 '17 at 22:28
  • But the purpose of this is after all the process on the view is passed to the controller. Meaning I am already expecting the model , the property name and the value of dropdownlist . how can i use that in the view side to output only what i need? – jon Jul 27 '17 at 22:28

0 Answers0