Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将剑道级联下拉列表绑定到列表中的列表属性_C#_Html_Asp.net Mvc_Kendo Ui_Frontend - Fatal编程技术网

C# 将剑道级联下拉列表绑定到列表中的列表属性

C# 将剑道级联下拉列表绑定到列表中的列表属性,c#,html,asp.net-mvc,kendo-ui,frontend,C#,Html,Asp.net Mvc,Kendo Ui,Frontend,我有两门课: class Enterprise { string EnterpriseCode {get; set;} string LocationCode {get; set;} List<FinYear> FinYears {get; set;} } class FinYear { string FinancialYear {get; set;} } 这三个字段应该是什么,以便DDL包含相关财务年度的列表 对于企业(如前一个下拉列表中所选)您

我有两门课:

class Enterprise
{
    string EnterpriseCode {get; set;}
    string LocationCode {get; set;}
    List<FinYear> FinYears {get; set;}
}

class FinYear
{
    string FinancialYear {get; set;}
}
这三个字段应该是什么,以便DDL包含相关财务年度的列表
对于企业(如前一个下拉列表中所选)

您不能从中级联,因为没有父-子关系。这意味着
FinYear
没有
ParentID
。您需要手动更改第二个组合框的数据源或实现连接

  • 子组合框将侦听父组合框值的任何更改
  • 如果父项没有值,则子项将被禁用

这里有一个:-它是
JavaScript
,但我认为您也可以轻松地为扩展修改它

HTML

<div class="demo-section k-header">
    <p>
        <label for="categories">Enterprises:</label><input id="categories" style="width: 270px" />
    </p>
    <p>
        <label for="products">FinYear:</label><input id="products" style="width: 270px" />
    </p>
</div>
var enterpriseArray = [{
  EnterpriseCode: "abc",
  LocationCode: "123",
  FinYears: [ "2014", "2015" ]
},
{
  EnterpriseCode: "def",
  LocationCode: "456",
  FinYears: [ "2012", "2013" ]
}];

$(document).ready(function() {
    var categories = $("#categories").kendoComboBox({                      
        placeholder: "Select Enterprise Code...",
        dataTextField: "EnterpriseCode",
        dataValueField: "EnterpriseCode",
        dataSource: enterpriseArray,
        change: function(e) {
          //debugger;
          products.dataSource.data(e.sender.dataItem().FinYears);
        }
    }).data("kendoComboBox");

    var products = $("#products").kendoComboBox({                       
        placeholder: "Select FinYear...",
        //dataTextField: "",
        //dataValueField: "",
    }).data("kendoComboBox");

});

“categories”组合框的数据源是否可以是传递给视图的模型?如果可能,你是如何做到的?当我尝试时,会出现javascript错误。还有,既然你在演示中得到了结果,comboBox和Dropdown(剑道)之间的区别是什么。1-是的,它可以,如果它不能,mvc是无用的:-)2-我认为这太广泛了,无法在这里回答。3-它们之间的唯一区别是:组合框允许用户从预定义的集合中选择值或输入自定义值。dropdownlist只允许选择一个预定义值。您是否可以编辑上述答案,以便数据源就是模型?@NehaAgrawal这是关于模型绑定的,内容非常广泛。我想我无法用几句话来解释它。根据您使用的方法(javascript或razor扩展),您需要为数据源或模型使用json,并且基于此,您需要相应地实现ActionResult以所需格式返回数据。谢谢。你的解决方案帮助我找到了书面答案……最终:)
<div class="demo-section k-header">
    <p>
        <label for="categories">Enterprises:</label><input id="categories" style="width: 270px" />
    </p>
    <p>
        <label for="products">FinYear:</label><input id="products" style="width: 270px" />
    </p>
</div>
var enterpriseArray = [{
  EnterpriseCode: "abc",
  LocationCode: "123",
  FinYears: [ "2014", "2015" ]
},
{
  EnterpriseCode: "def",
  LocationCode: "456",
  FinYears: [ "2012", "2013" ]
}];

$(document).ready(function() {
    var categories = $("#categories").kendoComboBox({                      
        placeholder: "Select Enterprise Code...",
        dataTextField: "EnterpriseCode",
        dataValueField: "EnterpriseCode",
        dataSource: enterpriseArray,
        change: function(e) {
          //debugger;
          products.dataSource.data(e.sender.dataItem().FinYears);
        }
    }).data("kendoComboBox");

    var products = $("#products").kendoComboBox({                       
        placeholder: "Select FinYear...",
        //dataTextField: "",
        //dataValueField: "",
    }).data("kendoComboBox");

});