我有一些任务:我有一个List,我从Controller传递View,但这个模型本身就是一个集合。我应该如何在构造方法中绑定一个列?
C#:
public static void GridColumns(List<ParameterCollection> model, MVCxGridViewColumnCollection columns)
{
columns.Add(??????????);
}
查看:
@model List<TFlex.DOCs.Model.Parameters.ParameterCollection>
@using TFlexDOCsWeb;
@Html.DevExpress().GridView(settings =>
{
settings.Name = "GridView";
//settings.ClientSideEvents.Init = "OnInit";
settings.KeyFieldName = "SystemFields.Id";
settings.SettingsBehavior.ConfirmDelete = true;
settings.CallbackRouteValues = new { Controller = "Catalogues", Action = "_GridViewPartial" };
settings.CommandColumn.Visible = true;
settings.CommandColumn.Caption = "*";
settings.CommandColumn.Width = System.Web.UI.WebControls.Unit.Percentage(5);
settings.SettingsPager.Visible = true;
settings.SettingsBehavior.AllowSelectByRowClick = false;
TFlexDOCsWeb.DevEx.GridViewBuilding.<bold>GridColumns</bold>(Model, settings.Columns);
var headerFilterMode = true ? HeaderFilterMode.CheckedList : HeaderFilterMode.List;
foreach (GridViewDataColumn column in settings.Columns)
column.Settings.HeaderFilterMode = headerFilterMode;
settings.Settings.ShowFilterRow = true;
settings.Settings.ShowFilterRowMenu = true;
}).Bind(Model).GetHtml()<bold>
</bold>
模型ParameterCollection包括from,其中parameter.Value = is value,parameter.ParameterInfo =此参数的Caption(字段名称)。我不知道如何为每个ParameterCollection Parameter.parameterInfo.name
绑定列名答案 0 :(得分:0)
您只需将其绑定到列表中所包含的对象上的属性名称,即您进行网格设置的列设置。 见下面简化的例子。
MODEL
namespace Some.Name.Space
{
public class RecipientListViewModel : List<RecipientViewModel> // HOwever you define your list
{
}
public class RecipientViewModel
{
public string Id {get; set;}
public string FullName { get; set; }
}
}
查看
@Html.DevExpress().GridView(settings =>
{
//General settings
settings.Name = "GridViewName";
settings.KeyFieldName = "Id"; // actual parameter name of keyfield on your object that is in your list
//other settings etc
settings.Columns.Add(column =>
{
column.Name = "FullName"; // actual parameter name on your object that is in your list that you want on the column
column.FieldName = "FullName"; // actual parameter name on your object that is in your list that you want on the column
column.Caption = LanguageHelper.GetText("UserConfig_Recipients_RecipientNameHeader");
//column.Width = System.Web.UI.WebControls.Unit.Pixel(200);
});
//other columns etc
}).Bind(YourModel).GetHtml()
CONTROLLER
public ActionResult Overview()
{
RecipientListViewModel model = PopulateInformationView(); // Populates the list with data
return View("YOURVIEWNAME", model);
}