设置初始组合框选择DevExpress Razor

时间:2013-08-13 15:49:32

标签: razor combobox devexpress

我只想在视图出现时选择“区域”值(这是其中一项)。这就是我所拥有的:

@Html.DevExpress( ).ComboBox( settings =>
{
    settings.Name = "cmbFieldLevel";
    settings.CallbackRouteValues = new { Controller = "Equipment", Action = "FieldLevelPartial" };
    settings.Properties.ValueType = typeof( string );
    settings.Properties.TextField = "AreaName";
    settings.Properties.ValueField = "AreaID";
    settings.Properties.EnableClientSideAPI = true;
    settings.ClientSideEvents.DataBound = "function( s, e ){ cmbFieldLevel.SelectedItem = "Area"; } ";
}).BindList(FieldLevel.GetAreaFilters()).GetHtml()

任何线索?

1 个答案:

答案 0 :(得分:1)

我能想到的两种方式。

  1. 如果您将ComboBox更改为ComboBox,则可以指定模型的值
  2. 喜欢这样

    @Html.DevExpress().ComboBoxFor(x => x.ParamOrderNo, settings =>
    {
          settings.Properties.ValueField = "OrderNo";
          settings.Width = 200;
          settings.Properties.TextField = "Name";
    }).BindList(CeduleProductionMVC.ViewModels.ViewModelCeduleGlobale.GetCommandes()).GetHtml()
    
    1. 此外,您可以设置SelectedIndex,如果您的组合内容是固定的,索引可能始终每次都相同。此外,如果列表未修复,您可以创建一个方法来检索索引并在此之后设置。