【问题标题】:DropDown list template in Kendo UI Grid MVC only showing first value of severalKendo UI Grid MVC中的下拉列表模板仅显示几个的第一个值
【发布时间】:2013-07-27 18:24:02
【问题描述】:

我已完成以下问题中显示的所有步骤:

How can I set and get the value of a dropdownlist in a grid in Kendo UI MVC?

但最后,只有我的列表的第一个值出现在下拉列表中。例如,只有“管理员”。我无法在弹出编辑模式中选择其他值(样式为下拉列表,但不会打开,并且值“admin”是唯一可见的)。

这是我的观点:

@(Html.Kendo().Grid<A.Models.Perm>()
    .Name("PermGrid")
    .Columns(columns =>
                 {
                     columns.Bound(r => r.Id).Visible(false);
                     columns.Bound(r => r.Name);
                     columns.Bound(r =>
                         r.PermType).EditorTemplateName("PermTypeEditor");
                     columns.Command(command =>
                                         {
                                             command.Edit() ;
                                         });
                 })
    .DataSource(datasoure => datasoure.Ajax()
                                .Model(model => model.Id(record => record.Id))
                                .Read(read => read.Action("GetAll", "Permi"))
                                .Update(update => update.Action("Update", 
                                    "Permi"))
                                .PageSize(10)
    )
    .Editable(editable => editable.Mode(GridEditMode.PopUp))
    .Sortable()
    .Selectable()
    .Events(e => e.Edit("onEdit"))
    .Pageable(pageable =>
                  {
                      pageable.Refresh(true);
                      pageable.PageSizes(true);
                  })
)

控制器:

public ActionResult GetAll([DataSourceRequest] DataSourceRequest request)
{
    var Permi = GetPermi();
    return Json(Permi.ToDataSourceResult(request, record => new
    {
        record.Id,
        record.Name,
        record.PermType,
    }));
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Update([DataSourceRequest] DataSourceRequest request, 
    Permission perm)
{

    if (perm != null && ModelState.IsValid)
    {
        _db.Update(perm);

        _db.SaveChanges();
    }

    return Json(ModelState.ToDataSourceResult());
}
private static IEnumerable<Permission> GetPermi()
{
    var dbs = new AFBContext();

    var list3 = (from Item1 in dbs.Permi.ToList() select Item1);
    return list3;
}

型号:

    public int Id { get; set; }

    public string Name { get; set; 

    [UIHint("PermTypeEditor")]
    public string PermType { get; set; }

模板编辑器:

@model string

@(Html.Kendo().DropDownList()
    .Name("PermType") 
    .Value(Model)
    .SelectedIndex(0)
    .BindTo(new string[] { "Admin", "Guest", "Normal" }))

好吧,它似乎适用于 Firefox 而不是 chrome。

【问题讨论】:

    标签: asp.net-mvc kendo-ui


    【解决方案1】:

    我也遇到了同样的问题,我现在可以让列表加载所有项目,但仅限于第一行

    在您的外键模板中:

    @(Html.DropDownList( "Column Name", new SelectList( new [] { "Admin", "Guest", "Normal" })))
    

    你的模型是正确的。

    控制器:

    public ActionResult PermType_Read( [DataSourceRequest] DataSourceRequest request )
    {
        return Json( GetPermiInfo().ToDataSourceResult( request ), JsonRequestBehavior.AllowGet );
    }
    
    private static IEnumerable<Permission> GetPermiInfo()
    {
        var permi = GetPermi()
    
        // Try setting your list up like this, using your model
        return permi.Select( permissionInfo => new Permission
        {
            Id = permissionInfo.Id,
            Name= blogCommentInfo.Name,
            PermType = permissionInfo.PermTypeId? // I'm not sure if you have Id's for your different types
        } );
    }
    

    查看:

    @(Html.Kendo().Grid<Permission>()
           .Name( "grid" )
           .Columns( columns =>
           {
               columns.Bound( f => f.Id ).Hidden();
               columns.Bound( f => f.Name );
               columns.ForeignKey( c => c.ForeignKey, new SelectList( new[]{
                   new {text="Admin",value = "1"},
                   new {text="Guest",value = "2"},
                   new {text="Normal",value = "3"},
               }, "value", "text" ) );
            } )
            .Pageable( pageable => pageable.ButtonCount( 5 ) )
            .Editable(ed=>ed.Mode(GridEditMode.InCell))
            .Scrollable()
            .DataSource( dataSource => dataSource
                .Ajax()
                .PageSize( 20 )
                .Model(model =>
                {
                    model.Id(b => b.Id);
                })
                .Update(up=>up.Action("Update","Permi"))
                .Read( read => read.Action( "PermType_Read", "Permi" ) )                            
            )
            .Selectable( select => select.Mode( GridSelectionMode.Single ) )
    )
    

    希望通过这个你可以更进一步,这绝不是你问题的正确答案,只是想帮助其他人可以帮助我们哈哈

    【讨论】:

    • 兴奋!同样的问题,只有第一行可见:(
    【解决方案2】:

    好的,这是旧的,但我发现问题出在哪里。 在那之前的一件事,问题自动修复,然后几天后出现。 我用萤火虫检查了页面,发现应用程序中有两个 Jquery/import 类的调用方法!一个在共享布局中,另一个在独特视图中(上一个)! 共享布局中的一个连接到 jquery 站点并下载最新的一个,但视图中的一个正在使用本地的。 起初,网络服务器防火墙阻止了第一个防火墙,站点运行顺利。但是当防火墙修复 jquery url 时,重复的 Jquery 调用/导入避免了 dropdown 正常工作。 所以我在解决问题时删除了第二个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多