Hi I have issue with displaying dropdownlist [object object]. I tried everyway and even followed some solution in this issue but none worked. Its simple SelectListItem Bind to dropdownlist. Value is loading without any list. when you click it it displays the list but when you select the list item nothing changed and remain as loaded displaying [Object Object]. but how ever Developer toolls shows Dropdownlist value and text field values. Could you please kindly tell me why and where I am wrong. I am new to Kendo but OK with MVC I have used all other dropDownList using Html helper methods even using models, Enums etc. but why this simple Vlaue, text list is not displaying and selecting. but loading perfectly. Please I am really stuck with other places as well with different kendo grid bind to different tables. Please note I am using ADO.NET and stored Proc to retrieve data as I am migrating to MVC. Please see attached images as well. Hope someone will give me solution to this burning issues. -Please note in my Drondownlist editor template, when I used read metid (Line 14 - 17) I get list as 'undefined' without displaying [object object]. its again same SelectListItem only thing is I manually bind to datasource via read method. Do i have to do anything in DropDownChnage event.
My Grid View.
_CategiryGrid.cshtml
@model IEnumerable<StB.ViewModels.CategoryViewModel>
@{
var imagePath =
"~\\Content\\images\\Info.gif"
;
}
@*
// Ajax Grid // *@
@*@(Html.Kendo().Grid(Model).Name(
"CategoryGrid"
)*@
@(Html.Kendo().Grid<StB.ViewModels.CategoryViewModel>().Name(
"CategoryGrid"
)
.Columns(columns =>
{
columns.Bound(c => c.ClientCode).Hidden(
true
);
columns.Bound(c => c.Category).ClientGroupHeaderTemplate(
"Category: "
+
"#= value#"
).Width(60);
columns.Bound(c => c.Attribute).Title(
"Attribute"
).Width(100);
columns.Bound(c => c.Description).Width(150);
//.ClientTemplate(@"<div><img id='tooltipIconItem' src='@imagePath' ToolTip =#:data:ToolTip# /></div>" + @"<div> @Html.Label('fieldValueItem', #:data:Description#)</div>");
columns.Bound(c => c.Required).Width(30);
//.ClientTemplate(@"<div><img id='reqEdit' src='~\\Content\\images\\RedStar.gif' /></div>");
columns.Bound(c => c.FieldType).Hidden(
true
);
columns.Bound(c => c.DomainID).Hidden(
true
);
columns.Bound(c => c.AttrType).Hidden(
true
);
columns.Bound(c => c.Tooltip).Hidden(
true
);
columns.Bound(c => c.FieldValue).Width(80).Title(
"Value"
).EditorTemplateName(
"FieldValueEditor"
).ClientTemplate(
"#:FieldValue #"
)
.HtmlAttributes(
new
{ id =
"ddlFieldvalues"
});
//.EditorTemplateName("FieldValueEditor");
})
.Editable(editabel => editabel.Mode(GridEditMode.InCell).Enabled(
true
))
.Navigatable()
.Scrollable()
.Groupable()
.Sortable()
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single).Type(GridSelectionType.Cell))
.AutoBind(
false
)
.Pageable(pageable => pageable
.ButtonCount(2))
.DataSource(datasource => datasource
.Ajax()
.Read(read => read.Action(
"DisplayGridData"
,
"HierarchyBuilder"
).Type(HttpVerbs.Post))
.Update(update => update.Action(
"UpdateCategory"
,
"HierarchyBuilder"
))
.ServerOperation(
false
)
.Batch(
true
)
.PageSize(60)
.Model(model => model.Id(p => p.Attribute))
.Model(model =>
{
model.Field(f => f.Category).Editable(
false
);
model.Field(f => f.Attribute).Editable(
false
);
model.Field(f => f.Description).Editable(
false
);
model.Field(f => f.Required).Editable(
false
);
model.Field(f => f.FieldValue).Editable(
true
).DefaultValue(
"1"
);
})
.Aggregates(aggregates => { aggregates.Add(p => p.Category == p.Category).Count(); })
.Group(groups => groups.Add(m => m.Category))
)
.Events(events => { events.Edit(
"onCategoryGridEdit"
).DataBound(
"onCategoryGridDataBound"
).Change(
"onCategoryGridChange"
); })
)
@Html.Hidden(
"ClientCode"
, HttpContext.Current.Session[
"ClientCode"
])
Model for Grid
CategoryViewModel
public
class
CategoryViewModel
{
public
string
OrgCode {
get
;
set
;}
public
string
SiteCode {
get
;
set
;}
public
string
ClientCode {
get
;
set
; }
public
string
StructureCode {
get
;
set
; }
public
string
Category {
get
;
set
; }
public
string
Attribute {
get
;
set
; }
public
string
Description {
get
;
set
; }
[UIHint(
"FieldValueEditor"
)]
public
string
FieldValue {
get
;
set
;}
public
string
AttrType {
get
;
set
; }
public
string
Required {
get
;
set
; }
public
int
FieldType {
get
;
set
; }
public
string
DomainID {
get
;
set
; }
public
string
Tooltip {
get
;
set
; }
public
IList<DomainViewModel> AllDomains {
get
;
set
; }
}
Controller Action method (this is where I get drodowlist as SelectListiem list. I initially directly bound to Domain List and it displays list prefectly but with [object object]. Then I changed to SelectList by creating SelectListItem by reading Domain Model and loading Vlaue text into SelectListItem. I bound to SelectList. Results exactly same. then Finally I chnaged to SelectListItem as show by kendo documentation. Its very simple text value list. and my Grid FieldVlaue in categoryViewModel is string value.
Below is my controller method
public
IEnumerable<SelectListItem> LoadDropDownlistForValueField(
string
type,
string
Client,
bool
required,
string
CurrentVal)
{
StB.DAL.Domain domainRepo =
new
DAL.Domain();
List<StB.Models.Domain> domains =
new
List<Models.Domain>();
domains = domainRepo.GetDomainValueList(type, Client, CurrentVal, required);
SelectListItem sli =
null
;
List<SelectListItem> selectlists =
new
List<SelectListItem>();
foreach
(var d
in
domains)
{
sli =
new
SelectListItem() { Text = d.ShortDescription, Value = d.Value, Selected = d.Value == CurrentVal };
selectlists.Add(sli);
}
ViewData[
"FieldValueList"
] = selectlists;
return
(System.Collections.Generic.IEnumerable<SelectListItem>)ViewData[
"FieldValueList"
];
}
below is my DropDownList editor template for my Grid column.
01.
@(Html.Kendo().DropDownList()
02.
.Name(
"FieldValue"
)
03.
.HtmlAttributes(
new
{ id =
"ddlFieldValues"
})
04.
.ValuePrimitive(
true
)
05.
.DataTextField(
"Text"
)
06.
.DataValueField(
"Value"
)
07.
08.
.AutoBind(
false
)
09.
10.
.Events(e => e.Change(
"onFiledVaueDropDownChange"
).DataBound(
"onFiledVaueDataBound"
))
11.
12.
.BindTo((IEnumerable<SelectListItem>)ViewData[
"FieldValueList"
])
13.
14.
//.DataSource(datasource =>
15.
//{
16.
// datasource.Read(read => read.Action("LoadDropDownlistForValueField", "HierarchyBuilder").Data("additionalInfo('CategoryGrid')"));
17.
//})
18.
19.
)