绑定KendoUi下拉列表

时间:2014-01-20 06:53:27

标签: asp.net-mvc-4 kendo-ui

我想根据ViewBag值letay ViewBag.Category过滤下面的ProductData下拉列表。我需要传递给GetProductData()的viewbag值。我怎么能做到这一点。谢谢

 $("#ProductData").kendoDropDownList({
            dataTextField: "OptionName",
            dataValueField: "OptionID",
            optionLabel: {
                OptionName: "Please Select",
                OptionID: ""
            },
            dataSource: {
                transport: { read: { url: '@(Url.Content("~/ProductDetails/GetProductData"))'} }
            }

        });



 <input type="ProductData" id="ProductData" name="ProductData" required validationMessage="Please select a product" style="width:110px; font-size:11px; margin-left:12px"/><span class="k-invalid-msg" data-for="ProductData"></span>

控制器:

//需要根据viewbag.category值进行过滤

public JsonResult GetProductData()
        {
            var productList = new TREntities();
            string Role = ViewBag.Role;
            return Json(productList .ConfigOptions.Select(c => new { OptionID = c.OptionID, OptionName = c.OptionName, OptionDetails = c.OptionDetails, OptionTypeID = c.ConfigTypeID })
                        .OrderBy(c => c.OptionName).Where(e => e.OptionID == 33), JsonRequestBehavior.AllowGet);

    }

1 个答案:

答案 0 :(得分:1)

 transport:{ read: {
            dataType: "json",
            url:  "ProductDetails/GetProductData",
            data: getTestData
        }}

      function getTestData() 
      {
              return {testID: parameterToSent}  // you can take parameterToSent from where you want
      };

public JsonResult GetProductData(string testID)
    {
       ...

    }