在我的 PartialView 中,我添加了一个带有列的网格,我需要以这种方式成为一个组合框。
settings.Columns.Add(column =>
{
column.FieldName = "TheFieldName";
column.Caption = "ACaption";
column.ColumnType = MVCxGridViewColumnType.ComboBox;
var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
comboBoxProperties.DataSource = ViewData["MyListOfObjects"];
comboBoxProperties.TextField = "Description";
comboBoxProperties.ValueField = "Description";
comboBoxProperties.ValueType = typeof(String);
});
ViewData 填充在控制器的 Index 方法中,并且我检查了它是否填充了包含值的对象。
** 编辑 ** 控制器代码:
public async Task Index() { if (TempDataId == null) return RedirectToActionPermanent("Index", "AnotherController");
// If you debug with Visual Studio the ViewData["MyListOfObjects"] is populated
ViewData["MyListOfObjects"] = await Worker.GetAllListOfObjects();
MyViewViewModel myViewViewModel = new MyViewViewModel
{
MyListOne = await Worker.GetAllListOfObjectsWithId(TempDataId),
MyListTwo = new List<AnotherObject>()
};
return View(tipomaViewViewModel);
}
数据访问 Entity Framework Code First 方法,GetAllListOfObjects:
public async Task<List<SimpleObjectEntity>> GetAllListOfObjects()
{
try
{
return await DataContext.SimpleObjectEntities.ToListAsync();
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
return null;
}
带有部分 GridView 的索引视图
@model Models.ViewViewModel.MyViewViewModel
@using Internationalization
@{
Html.EnableClientValidation();
ViewBag.Title = Resources.MenuLeftBar;
}
<h4>@Resources.Menu- @Resources.MenuLeftBar</h4>
<div>@Html.Partial("AGridViewPartial", Model.MyListOne)</div>
<br/>
<div>@Html.Partial("AnotherWithComboboxColumnGridViewPartial", Model.MyListTwo)</div>
PopupEditForm 中的组合框没有显示任何内容。
知道有什么问题吗?
问候。