我无法让 DropDownList 显示在 Telerik MVC 网格的单元格中。我遵循了一个运行良好的教程项目,我看不出它为什么不起作用的任何差异。需要注意的是,这是一个区域,而教程不是。有任何想法吗?
模型(位于单独的项目 - \External\KPI\KPI.Business.Entities\Kpi.cs):
public sealed class Kpi
{
#region Properties
/// <summary>
/// Gets or sets the KpiId.
/// </summary>
/// <value>The KpiId.</value>
public long KpiId { get; set; }
/// <summary>
/// Gets or sets the Organization Id.
/// </summary>
/// <value>The Organization Id.</value>
public string OrganizationId { get; set; }
/// <summary>
/// Gets or sets the channel.
/// </summary>
/// <value>
/// The channel.
/// </value>
[UIHint("Channel"), Required]
public string Channel { get; set; }
}
控制器(位于 UI 项目 - \Areas\KPI\Controllers\KpiController.cs):
public ActionResult Index(string organizationId)
{
if (!string.IsNullOrEmpty(organizationId))
{
initializeEditMode(organizationId);
ViewBag.CustomerOrg = new OrganizationLogic(organizationId, Session["connectionString"].ToString()).GetName();
var channels = new OrganizationLogic(organizationId, Session["connectionString"].ToString()).GetOrganizations();
ViewBag.Channels = channels.Select(x => x.Name).ToArray();
}
return View();
}
部分视图(位于 UI 项目 - \Areas\KPI\Views\Kpi\Editor Templates\Channel.cshtml):
@using System.Collections
@using Telerik.Web.Mvc.UI
@model string
@(Html.Telerik().DropDownList()
.Name("Channel")
.BindTo(new SelectList((IEnumerable)ViewData["channels"], "OrganizationId", "Name"))
)
视图(位于 UI 项目 - \Areas\KPI\Views\Kpi\Index.cshtml):
@using KPI.Business.Entities
@using Telerik.Web.Mvc.UI
@model IList<KPI.Business.Entities.Kpi>
@{
ViewBag.Title = "KPI";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>
@ViewBag.CustomerOrg
</h2>
<div>
@(Html.Telerik().Grid<Kpi>()
.Name("kpiGrid")
.ToolBar(commands => commands
.Insert()
.ButtonType(GridButtonType.ImageAndText)
.ImageHtmlAttributes(new { style = "margin-left:0" })
.Text("Insert New KPI"))
.DataKeys(keys => keys.Add(v => v.KpiId))
.Columns(columns =>
{
columns.Bound(kpi => kpi.KpiId).Hidden(true);
columns.Bound(kpi => kpi.OrganizationId).Hidden(true);
columns.Bound(kpi => kpi.Channel);
columns.Bound(kpi => kpi.Name).Column.Title = "KPI Name";
columns.Bound(kpi => kpi.Value);
columns.Bound(kpi => kpi.StartDate).Width(150).Format("{0:d}");
columns.Bound(kpi => kpi.EndDate).Width(150).Format("{0:d}");
columns.Command(commands => commands.Edit().ButtonType(GridButtonType.Image)).Width(40);
})
.DataBinding(binding => binding
.Ajax()
.Select("KpiEditTemplate", "Kpi")
.Insert("InsertKpi", "Kpi")
.Update("UpdateKpi", "Kpi"))
.ClientEvents(events => events.OnRowDataBound("Grid_onRowDataBound").OnSave("Grid_onSave").OnError("checkForSessionTimeout"))
.Pageable()
.Sortable()
.Filterable()
.Selectable()
)
@(Html.Telerik().Window()
.Name("Window")
.Visible(false)
.Width(300)
.Height(200)
.Modal(true)
)
</div>