C# 使用MVC Razor语法访问filtersource

C# 使用MVC Razor语法访问filtersource,c#,asp.net-mvc,kendo-ui,asp.net-mvc-5,C#,Asp.net Mvc,Kendo Ui,Asp.net Mvc 5,我如何实现下面所示的MVC Razor中的change:function(e)?这几天来,我一直在用我的头敲打它,什么也找不到 $(document).ready(function() { var items = [ {value : '1', desc : 'fred'}, {value : '2', desc : 'wilma'}, {value : '3', desc : 'pebbles'}, {value : '4',

我如何实现下面所示的MVC Razor中的
change:function(e)
?这几天来,我一直在用我的头敲打它,什么也找不到

$(document).ready(function() {
var items = [
    {value : '1',
     desc : 'fred'},
    {value : '2',
     desc : 'wilma'},
    {value : '3',
     desc : 'pebbles'},
    {value : '4',
     desc : 'dino'}
];

var cb = $('#comboBox').kendoComboBox({
    dataSource : items,
    dataTextField : 'desc',
    dataValueField : 'value',
    filter : 'contains',
    change : function (e) {
        if (this.value() && this.selectedIndex == -1) {    
            this._filterSource({
                value: "",
                field: this.options.dataTextField,
                operator: "contains"
            });
            this.select(1);
        }
    }
}).data('kendoComboBox');

$('#showValue').click(function () {
    alert(cb.value());
});

});
这里的工作示例-->


这是我到目前为止所拥有的。如果语句没有任何作用,那么
语句中会有什么内容

function onChange(e) {
    var lT = $("#loadType").data("kendoComboBox").input.val();
    if (lT != "Generic") {
        // Here I need to compare what's entered to what is populated in the comboBox dropdown
        if (this.selectedIndex == -1) {
            this._filterSource({ 
                value: "",
                field: this.options.dataTextField,
                operator: "contains"
            });
            this.select(1);

                //this is for Testing purposes only
                alert("See Me?");
            }

        //this is for Testing purposes only
        alert(lT + " " + this.selectedIndex + " " + this.value());
    }
};
为了完整起见,这里还有组合框:

<div class="form-group">
        @Html.LabelFor(model => model.loadDescrip, new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @(Html.Kendo().ComboBox()
                    .Name("loadDescrip")
                    .Filter(FilterType.Contains)
                    .DataTextField("DocCode")
                    .DataValueField("DocCode")
                    .DataSource(source =>
                    {
                        source.Read(read =>
                        {
                            read.Action("GetCascadeDocumentNumbers", "DockDoor")
                                .Data("filterLoadDescription");
                        })
                      .ServerFiltering(true);
                    })
                    .Enable(false)
                    .AutoBind(false)
                    .CascadeFrom("loadType")
                    .Events(e =>
                        {
                e.Change("onChange");
                        })
            )
            @Html.ValidationMessageFor(model => model.loadDescrip)
        </div>
    </div>

@LabelFor(model=>model.loadDescrip,新的{@class=“controllabel col-md-2”})
@(Html.Kendo().ComboBox())
.名称(“loadDescrip”)
.Filter(FilterType.Contains)
.DataTextField(“DocCode”)
.DataValueField(“DocCode”)
.DataSource(source=>
{
source.Read(Read=>
{
读.操作(“GetCascadeDocumentNumber”,“DockDoor”)
.数据(“filterLoadDescription”);
})
.ServerFiltering(true);
})
.Enable(false)
.AutoBind(假)
.CascadeFrom(“加载类型”)
.事件(e=>
{
e、 变更(“变更”);
})
)
@Html.ValidationMessageFor(model=>model.loadDescrip)

您可以通过两种方式处理Razor中的事件:

  • 指定事件处理程序的名称

    @(Html.Kendo().ComboBox()
          .Name("combobox")
          .Events(events => events.Change("combobox_change"))
    )
    <script>
    function combobox_change(e) {
      // handle the event
    }
    </script>
    
    @(Html.Kendo().ComboBox())
    .Name(“组合框”)
    .Events(Events=>Events.Change(“组合框_Change”))
    )
    函数组合框\u更改(e){
    //处理事件
    }
    
  • 将事件处理程序定义为Razor模板委托

    @(Html.Kendo().ComboBox()
      .Name("combobox")
      .Events(events => events.Change(@<text>
          function(e) {
             // handle the event
          }
      </text>))
    )
    
    @(Html.Kendo().ComboBox())
    .Name(“组合框”)
    .Events(Events=>Events.Change(@
    职能(e){
    //处理事件
    }
    ))
    )
    

  • 更多信息可在此处找到:

    实际问题是什么?是否需要将其转换为服务器包装语法?是的,特别是更改事件。我似乎不知道如何在服务器包装器语法中实现其中的内容。问题是,当您尝试使用“loadType”获取组合框时,组合框的名称为“loadDescrip”。不,“loadType”是另一个组合框。它们处于级联关系中。我把那件事漏掉了,认为这没有关系。如果有帮助的话可以包括在内。我就是无法让
    \u filterSource
    选择(1)
    工作。他们似乎什么都没做。对不起,我现在明白了,我不是很清楚。我有一个事件,我就是不能让示例事件中的代码在我的版本中工作。我将用我的代码修改这个问题。谢谢你的帮助!