【问题标题】:Kendo dropdownlist cascade third level not showing optionlabel剑道下拉列表级联第三级不显示选项标签
【发布时间】:2014-02-12 10:55:29
【问题描述】:

我有三个带级联的剑道下拉列表,第一个和第二个是正确的,但第三个在页面加载时没有显示选项标签。

如您所见,“Ciudad”下拉列表没有显示 optionLabel,即使它有它,如控制台所示。

我不知道为什么会这样,因为它与剑道演示中的示例相同:

Link to demo

这是razor中的代码:

        <div class="baseControlsLine rowLineHeight lineMap">
            <div class="labelControlWith"> @Html.Label(@BackOffice.lblCountry + ":", htmlAttributes: new { @class = "baseLabel mapLabel" })</div>
            <div class="baseControlSmall">
                @(Html.Kendo().DropDownListFor(c => c.Customer.MapCountry)
                    .OptionLabel(BackOffice.txtSelectCountry)
                    .Events(e => e.Close("CustomerCreateEdit.CreateAddresMap").DataBound("CustomerCreateEdit.DataBound"))
                    .DataTextField("Text")
                    .DataValueField("Value").HtmlAttributes(new { @class = "baseTextbox" })
                    .DataSource(source => {
                        source.Read(read => {
                            read.Action(Constants.GET_COUNTRIES_SELECT_LIST, Constants.CUSTOMER_CONTROLLER);
                        });
                    }))
                @Html.ValidationMessageFor(model => model.Customer.MapCountry)
            </div>
        </div>
        <div class="baseControlsLine rowLineHeight lineMap">
            <div class="labelControlWith"> @Html.Label(@BackOffice.lblProvince + ":", htmlAttributes: new { @class = "baseLabel mapLabel" })</div>
            <div class="baseControlSmall">
                @(Html.Kendo().DropDownListFor(c => c.Customer.MapProvince)
                    .Events(e => e.Close("CustomerCreateEdit.CreateAddresMap"))
                    .OptionLabel(BackOffice.txtSelectProvince)
                    .DataTextField("Text")
                    .DataValueField("Value").HtmlAttributes(new { @class = "baseTextbox" })
                    .CascadeFrom("Customer_MapCountry")
                    .DataSource(source => {
                        source.Read(read => {
                            read.Action(Constants.GET_PROVINCES_SELECT_LIST, Constants.CUSTOMER_CONTROLLER).Data("CustomerCreateEdit.GetCountryId");
                        }).ServerFiltering(true);
                    }))
                @Html.ValidationMessageFor(model => model.Customer.MapProvince)
            </div>
        </div>
        <div class="baseControlsLine rowLineHeight lineMap">
            <div class="labelControlWith"> @Html.Label(@BackOffice.lblCity + ":", htmlAttributes: new { @class = "baseLabel mapLabel" })</div>
            <div class="baseControlSmall">
                @(Html.Kendo().DropDownListFor(c => c.Customer.MapCity)
                    .Events(e => e.Close("CustomerCreateEdit.CreateAddresMap"))
                    .OptionLabel(BackOffice.txtSelectCity)
                    .DataTextField("Text")
                    .DataValueField("Value").HtmlAttributes(new { @class = "baseTextbox" })
                    .CascadeFrom("Customer_MapProvince")
                    .DataSource(source => {
                        source.Read(read => {
                            read.Action(Constants.GET_CITIES_SELECT_LIST, Constants.CUSTOMER_CONTROLLER).Data("CustomerCreateEdit.GetProvinceId");
                        }).ServerFiltering(true);
                    }))
                @Html.ValidationMessageFor(model => model.Customer.MapCity)
            </div>
        </div>

这里是javascript的代码:

    GetCountryId: function () {
    /// <signature>
    ///   <summary>Devuelve el id del country para la cascada.</summary>
    /// </signature>
    return {
        id: $("#Customer_MapCountry").val()
    };
},
GetProvinceId: function () {
    /// <signature>
    ///   <summary>Devuelve el id de la provincia para la cascada.</summary>
    /// </signature>
    return {
        id: $("#Customer_MapProvince").val()
    };
},

这里是控制器:

    public JsonResult GetCitiesSelectList(int? id) {
        if (!id.HasValue)
            return Json(new SelectListItem() { Text = BackOffice.txtSelectCity }, JsonRequestBehavior.AllowGet);
        List<CityLanguage> listCity = _applicationCity.GetAllWithLanguage(id.Value).ToList();
        return Json(new SelectList(listCity, "IdCity", "Name"), JsonRequestBehavior.AllowGet);
    }
    public JsonResult GetProvincesSelectList(int? id) {
        if (!id.HasValue)
            return Json(new SelectListItem() { Text = BackOffice.txtSelectProvince }, JsonRequestBehavior.AllowGet);
        List<ProvinceLanguage> listProvince = _applicationProvince.GetAllWithLanguage(id.Value).ToList();
        return Json(new SelectList(listProvince, "IdProvince", "Name"), JsonRequestBehavior.AllowGet);
    }
    public JsonResult GetCountriesSelectList() {
        List<CountryLanguage> listCountryLanguage = _applicationCountry.GetAllWithLanguage().ToList();
        return Json(new SelectList(listCountryLanguage, "IdCountry", "Name"), JsonRequestBehavior.AllowGet);
    }

编辑:

我的 jquery 版本有问题,我不得不按这个顺序放置 javascript:

jquery。 剑道。 jquery-ui。

有可能是javascripts的顺序出错了?

我还有一个 jquery 版本,它不是剑道附带的版本。

其中一些可能会导致第三个下拉列表的奇怪行为?

【问题讨论】:

  • 显示下拉列表代码以便我们为您提供帮助。
  • 我已经编辑了这个问题,谢谢。

标签: jquery asp.net-mvc razor kendo-ui kendo-dropdown


【解决方案1】:

您好,试试Placeholder insted of OptionLabel

 @(Html.Kendo().DropDownListFor(c => c.Customer.MapCountry)
                    .Placeholder(BackOffice.txtSelectCountry)
                    .Events(e => e.Close("CustomerCreateEdit.CreateAddresMap").DataBound("CustomerCreateEdit.DataBound"))
                    .DataTextField("Text")
                    .DataValueField("Value").HtmlAttributes(new { @class = "baseTextbox" })
                    .DataSource(source => {
                        source.Read(read => {
                            read.Action(Constants.GET_COUNTRIES_SELECT_LIST, Constants.CUSTOMER_CONTROLLER);
                        });
                    }))

【讨论】:

  • 嗨 Jaimin,抱歉,我的剑道版本中没有占位符选项,我想我有最后一个。
  • @AlbertCortada 好的,那么我必须检查一下。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-31
  • 1970-01-01
  • 2017-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多