1

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

如何在 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。

4

2 回答 2

0

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

在您的外键模板中:

@(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 ) )
)

希望有了这个你可以走得更远,这绝不是你问题的正确答案,只是想帮助其他人可以帮助我们哈哈

于 2013-07-31T09:41:44.237 回答
0

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

于 2014-01-09T11:47:58.187 回答