在剑道网格dropdownlist不工作 [英] dropdownlist in kendo grid not working

查看:154
本文介绍了在剑道网格dropdownlist不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用incell编辑和使用 http:// demos。 telerik.com/aspnet-mvc/grid/editing-custom ,但无法找到我的部分视图,应该从下拉列表中显示。



部分view(Testview.cshtml)

  @using Kendo.Mvc.UI 

@(Html.Kendo ().DropDownList()
.Name(ResourceType)//该小部件的名称应该与该属性的名称相同
.DataValueField(Id)//下拉取自EmployeeID属性
.DataTextField(Name)//项目的文本取自EmployeeName属性
.BindTo((System.Collections.IEnumerable)ViewData [defaultResourceType ])//在控制器中填充所有员工的列表



这是我的网格:

  @(Html.Kendo()。Grid< RMS .Admin.ViewModel&克t;()
.Name(ResourceGrid)
.Columns(columns =>
{
columns.Bound(c => c.ResourceId).Hidden();
columns.Bound(c => c.ResourceName);
columns.Bound(c => c.Descritption);
columns.Bound(c => c.ResourceType.Name).ClientTemplate(#= ResourceType.Name#);
columns.Bound(c => c.Approved);
columns.Bound(c => c.IsEnabled);
columns.Command(command =>
{
command.Edit();
command.Destroy();
})。Width(172).Title ( 编辑/删除);
。)
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Scrollable( )
.Sortable()
.Pageable(pageable =>可分页的
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
model.Id(s => s.ResourceId );
model.Field(s => s.ResourceType).DefaultValue(ViewData [defaultResourceType] as RMS.Admin.ViewModel.ResourceTypeId);
})
.Create( update => update.Action(CreateResource,Home))
.Read(read => read.Action(ReadResource,Home))
.Update(update = > update.Action(SaveSystem,Home))
.Destroy(destroy => destroy.Action(RemoveSystem,Home))



以下是我的模型的一部分:

  public string ResourceUserId {get;组; } 
[UIHint(Testview)]
public ResourceTypeId ResourceType {get;组; }

这是在我绑定数据的控制器中:

  private void GetResourceTypeId()
{
// string [] list = new string [] {Image,Document,其他};
IList< ViewModel.ResourceTypeId> list = new List< ViewModel.ResourceTypeId>();

var a = new ViewModel.ResourceTypeId
{
Name =Image,
Id = 1
};
var b = new ViewModel.ResourceTypeId
{
Name =Document,
Id = 2
};
var c = new ViewModel.ResourceTypeId
{
Name =Other,
Id = 3
};

list.Add(a);
list.Add(b);
list.Add(c);
ViewData [defaultResourceType] = list.First();
}

试图渲染网格时出现此错误:
您正在查找的资源(或其某个依赖项)可能已被删除,名称已更改或暂时不可用。请检查以下网址并确保它拼写正确。



我缺少什么?

解决方案

ViewData [defaultResourceType] = list.First(); 绑定一个项目。相反,您应该绑定到整个列表,然后使用 .Value(1)设置默认选项,以便默认情况下具有图片。

  @(Html.Kendo()。DropDownList()
.Name(ResourceType)
.DataValueField(Id )
.DataTextField(Name)
.BindTo((System.Collections.IEnumerable)ViewData [ResourceTypeList])
.Value(ViewData [DefaultResourceType])
);






另外,对于MVC中的列模板,可能只是想用EditorTemplateName设置它
$ b $ pre $ columns.Bound(e => e.myColumn).EditorTemplateName(dropdownTemplate )

然后定义要在页面上的其他位置使用的模板。

 < script id =dropdownTemplatetype =text / x-kendo-template> 
@(Html.Kendo()。DropDownList()
.Name(myDropDown)
.....
.ToClientTemplate()

< / script>



如果您希望还可以将其声明为独立模板在你的/ Views / Shared /文件夹中。您不必添加 .ToClientTemplate()或脚本标记。你可以通过文件名引用它。然后,您可以在项目中的多个页面上使用该模板。


Im trying to use incell editing and use of the http://demos.telerik.com/aspnet-mvc/grid/editing-custom but is can't find my partial view that the dropdownlist should be rendered from.

Partial view (Testview.cshtml)

   @using Kendo.Mvc.UI

 @(Html.Kendo().DropDownList()
        .Name("ResourceType") // Name of the widget should be the same as the name of the property
.DataValueField("Id") // The value of the dropdown is taken from the EmployeeID property
.DataTextField("Name") // The text of the items is taken from the EmployeeName property
    .BindTo((System.Collections.IEnumerable)ViewData["defaultResourceType"]) // A list     of all employees which is populated in the controller

)

This is my grid:

  @(Html.Kendo().Grid<RMS.Admin.ViewModel>()
  .Name("ResourceGrid")
  .Columns(columns =>
  {
      columns.Bound(c => c.ResourceId).Hidden();
      columns.Bound(c => c.ResourceName);
      columns.Bound(c => c.Descritption);
      columns.Bound(c => c.ResourceType.Name).ClientTemplate("#=ResourceType.Name#");
      columns.Bound(c => c.Approved);
      columns.Bound(c => c.IsEnabled);
      columns.Command(command =>
      {
          command.Edit();
          command.Destroy();
      }).Width(172).Title("Edit/Delete");
  })
  .ToolBar(toolbar => toolbar.Create())
  .Editable(editable => editable.Mode(GridEditMode.InCell))
  .Scrollable()
  .Sortable()
  .Pageable(pageable => pageable
      .Refresh(true)
      .PageSizes(true)
      .ButtonCount(5))
  .DataSource(dataSource => dataSource
      .Ajax()
      .Model(model =>
      {
          model.Id(s => s.ResourceId);
          model.Field(s => s.ResourceType).DefaultValue(ViewData["defaultResourceType"] as RMS.Admin.ViewModel.ResourceTypeId);
      })
      .Create(update => update.Action("CreateResource", "Home"))
            .Read(read => read.Action("ReadResource", "Home"))
            .Update(update => update.Action("SaveSystem", "Home"))
            .Destroy(destroy => destroy.Action("RemoveSystem", "Home"))
    )

)

Here is a part of my model:

  public string ResourceUserId { get; set; }
    [UIHint("Testview")]
    public ResourceTypeId ResourceType { get; set; }

This is in my controller where i bind the data:

    private void GetResourceTypeId()
    {
        //string [] list = new string[]{"Image", "Document", "Other"};
        IList<ViewModel.ResourceTypeId> list = new List<ViewModel.ResourceTypeId>();

        var a = new ViewModel.ResourceTypeId
        {
            Name = "Image",
            Id = 1
        };
        var b = new ViewModel.ResourceTypeId
        {
            Name = "Document",
            Id = 2
        };
        var c = new ViewModel.ResourceTypeId
        {
            Name = "Other",
            Id = 3
        };

        list.Add(a);
        list.Add(b);
        list.Add(c);
        ViewData["defaultResourceType"] = list.First();    
    }

I get this error when trying to render the grid: The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

What am i missing?

解决方案

First off your trying to bind just to one item with ViewData["defaultResourceType"] = list.First();. Instead you should bind to your whole list and then set the default option with .Value("1") so that it has "Images" by default.

@(Html.Kendo().DropDownList()
  .Name("ResourceType") 
  .DataValueField("Id")
  .DataTextField("Name")
  .BindTo((System.Collections.IEnumerable)ViewData["ResourceTypeList"])
  .Value(ViewData["DefaultResourceType"])
);


Also for a template for a column in MVC you may just want to set it with EditorTemplateName

columns.Bound(e => e.myColumn).EditorTemplateName("dropdownTemplate")

And then define the template that you want to use somewhere else on the page.

<script id="dropdownTemplate" type="text/x-kendo-template">
  @(Html.Kendo().DropDownList()
    .Name("myDropDown")
    .....
    .ToClientTemplate()
  )
</script>


If you would like you can also declare it as a stand alone template in your /Views/Shared/ folder. You would not have to add the .ToClientTemplate() or the script tags. You would reference it by the file name. You could then use the template on multiple pages in the project.

这篇关于在剑道网格dropdownlist不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆