0

我无法让 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>
4

2 回答 2

3

Telerik 文档不是最新的,因此它没有告诉您可以使用更简单的语法。我在这样的事情上取得了成功。不需要UIHint属性。

@(Html.Telerik().Grid<MyViewModel>()
  .Name("Grid")
  .Columns(cols =>
    {
      cols.Bound(o => o.Property1);
      cols.Bound(o => o.Property2)
          .EditorTemplateName("Property2Template"); // this your .cshtml filename
    })
  .DataBinding(binding =>
    {
       //etc
    })
  // remainder of grid code
)

您的编辑器模板应位于您所在区域的 Views/Shared/EditorTemplates 目录中。希望有帮助。

于 2013-09-16T22:55:37.040 回答
0

据我所知,即使您有一个区域,编辑器模板也需要相对于 _Layout.cshtml。我确定在某个地方设置了这个设置,我只是没有看到它。我从以前的工程师那里继承了这个应用程序,并移动了那个文件让它为我工作。

于 2013-09-10T14:29:55.703 回答