2013-06-19 3 views
0

Привет, я использую сетку Kendo с раскрывающимся списком, я последовал за демо в http://demos.kendoui.com/web/grid/foreignkeycolumn.html , но Im, получив эту ошибку «DataBinding:« System.Web.Mvc.SelectListItem »не содержит свойства с именем ' Я бы'".Kendo Grid с DropdownList

Может ли кто-нибудь помочь мне сделать мой код без ошибок?

вот мой ViewModel:

public class AccountingViewModel 

{ 
    private string _code = string.Empty; 

    private string _description = string.Empty; 

    public int Id 
    { 
     get;set; 
    } 

    public string Code 
    { 
     get { return _code; } 
     set { _code = value; } 
    } 

    public string Description 
    { 
     get { return _description; } 
     set { _description = value; } 
    } 

    public int MajorCategoryId 
    { 
     get;set; 
    } 

    public SelectList MajorCategories 
    { 
     get;set; 
    } 
} 

Вот мой контроллер:

public ActionResult Index() 

    { 
     var majorCategory = new SelectList(new[] 
             { 
              new {Id="1",Name="Category1"}, 
              new{Id="2",Name="Category2"}, 
              new{Id="3",Name="Category3"}, 
             }, 
         "Id", "Name", 1); 

     ViewData["majorCategories"] = majorCategory; 

     return View(accountingService.GetAllAccountings()); 

    } 

Вот мой индекс Вид:

@model IEnumerable <PPMS.Model.ViewModels.AccountingViewModel> 
<br/> 

< div class="k-grid" > 

@(Html.Kendo().Grid(Model) 
.Name("grid") 
.Columns(columns => 
     { 
      columns.Bound(p => p.Code); 
      columns.Bound(p => p.Description).Width(150); 
       columns.ForeignKey(p => p.MajorCategoryId, (System.Collections.IEnumerable)ViewData["majorCategories"], "Id", "Name") 
          .Title("MajorCategory").Width(150); 

     columns.Command(command => command.Destroy()).Width(110); 
        }) 
     .ToolBar(toolBar => 
        { 
         toolBar.Save(); 
         toolBar.Create(); 
        }) 
     .Editable(editable => editable.Mode(GridEditMode.InCell)) 
     .Filterable() 
     .Groupable() 
     .Pageable()  
     .Scrollable() 
     .HtmlAttributes(new { style = "height:430px;" })  
     .DataSource(dataSource => dataSource 
        .Ajax() 
        .Batch(true) 
        .PageSize(20) 
        .ServerOperation(false) 
        .Events(events => events.Error("errorHandler")) 
        .Model(model => 
            { 
             model.Id(p => p.Id); 
             model.Field(p => p.Id).Editable(false); 
            model.Field(p => p.MajorCategoryId).DefaultValue(1);  
               }) 

         .Create(create => create.Action("Create", "Accounting")) 
         .Read(read => read.Action("Index", "Accounting")) 
         .Update(update => update.Action("Edit", "Accounting")) 
         .Destroy(destroy => destroy.Action("Delete", "Accounting")) 
     ) 
    ) 
</div> 
<br/> 


<script type="text/javascript"> 


function errorHandler(e) { 
    if (e.errors) { 
     var message = "Errors:\n"; 
     $.each(e.errors, function (key, value) { 
      if ('errors' in value) { 
       $.each(value.errors, function() { 
        message += this + "\n"; 
       }); 
      } 
     }); 
     alert(message); 
    } 
} 


</script> 

Я обновил свой взгляд на и сейчас привязка selectlist к проблеме теперь ее отображение текстового поля внутри сетки вместо выпадающего списка .. вот мой обновленный Индексный:

Вот мой индекс Вид:

@model IEnumerable <PPMS.Model.ViewModels.AccountingViewModel> 
<br/> 

< div class="k-grid" > 

@(Html.Kendo().Grid(Model) 
.Name("grid") 
.Columns(columns => 
     { 
      columns.Bound(p => p.Code); 
      columns.Bound(p => p.Description).Width(150); 
       columns.ForeignKey(p => p.MajorCategoryId, (System.Collections.IEnumerable)ViewData["majorCategories"], "Value", "Text") 
          .Title("MajorCategory").Width(150); 

     columns.Command(command => command.Destroy()).Width(110); 
        }) 
     .ToolBar(toolBar => 
        { 
         toolBar.Save(); 
         toolBar.Create(); 
        }) 
     .Editable(editable => editable.Mode(GridEditMode.InCell)) 
     .Filterable() 
     .Groupable() 
     .Pageable()  
     .Scrollable() 
     .HtmlAttributes(new { style = "height:430px;" })  
     .DataSource(dataSource => dataSource 
        .Ajax() 
        .Batch(true) 
        .PageSize(20) 
        .ServerOperation(false) 
        .Events(events => events.Error("errorHandler")) 
        .Model(model => 
            { 
             model.Id(p => p.Id); 
             model.Field(p => p.Id).Editable(false); 
            model.Field(p => p.MajorCategoryId).DefaultValue(1);  
               }) 

         .Create(create => create.Action("Create", "Accounting")) 
         .Read(read => read.Action("Index", "Accounting")) 
         .Update(update => update.Action("Edit", "Accounting")) 
         .Destroy(destroy => destroy.Action("Delete", "Accounting")) 
     ) 
    ) 
</div> 
<br/> 


<script type="text/javascript"> 


function errorHandler(e) { 
    if (e.errors) { 
     var message = "Errors:\n"; 
     $.each(e.errors, function (key, value) { 
      if ('errors' in value) { 
       $.each(value.errors, function() { 
        message += this + "\n"; 
       }); 
      } 
     }); 
     alert(message); 
    } 
} 


</script> 

ответ

0

Перечень иностранных выпадающий должен содержать элементы, которые имеют «значение» и свойство «текст»?

Как:

вар категории = [{ "значение": 1, "Текст": "Напитки" }, { "значение": 2, "Текст": «Приправы " } }];

Смежные вопросы