Hi,
I'm trying to create a dropdown into a gridview, and I have tried lots op things.
the thing I'm stuck with now is this error
"The call is ambiguous between the following methods or properties: 'Kendo.Mvc.UI.Fluent.DropDownListBuilder.BindTo(System.Collections.Generic.IEnumerable<Kendo.Mvc.UI.DropDownListItem>)' and 'Kendo.Mvc.UI.Fluent.DropDownListBuilder.BindTo(System.Collections.Generic.IEnumerable<System.Web.Mvc.SelectListItem>)'"
in the Bindto I have a list of items which I load from the viewbag.
But I can't get pass this error.
do U need to unreference something?
thank you.
4 Answers, 1 is accepted
Could you provide the code that you are using for the dropdownlist and to add the ViewBag entry? The error indicates the ViewBag entry is not set or is set to null.
Regards,
Daniel
Telerik

Hi Daniel,
I have changed the source now so the dropdownlist is static, but it's not as it should be off course.
what I had was the following
in shared views I have a folder with EditorTemplates and in it I have this template "StatusDdl.cshtml"
@
using
Kendo.Mvc.UI;
@model
int
@(Html.Kendo().DropDownList()
.Name(
"Status"
)
.Value(Model.ToString())
.SelectedIndex(0)
.BindTo(ViewBag.StatusDdl)
.HtmlAttributes(
new
{ style =
"width:250px"
})
.ValuePrimitive(
true
)
)
public
ActionResult Users_Read([DataSourceRequest]DataSourceRequest request)
{
List<UserStatus> UserStatus = db.UserStatus.ToList();
ViewBag.StatusDdl = UserStatus;
IQueryable<Users> users = db.Users;
DataSourceResult result = users.ToDataSourceResult(request, user =>
new
{
Id = user.Id,
UserId = user.UserId,
Name = user.Name,
Email = user.Email,
Password = user.Password,
Status = user.Status,
//UserStatus = new Teunesen_Bestandsbeheer.Models.UserStatus()
//{
// Id = user.UserStatus.Id,
// Status = user.UserStatus.Status
//},
Admin = user.Admin,
Language = user.Language,
});
return
Json(result);
}
and the view itself looks like this.
@(Html.Kendo().Grid<Teunesen_Bestandsbeheer.Models.Users>()
.Name(
"grid"
)
.Columns(columns =>
{
columns.Bound(c => c.Name).Title(
"Naam"
).HtmlAttributes(
new
{ @
class
=
"edit-col"
});
columns.Bound(c => c.Email).Title(
"Email"
).HtmlAttributes(
new
{ @
class
=
"edit-col"
});
//columns.ForeignKey(c => c.Status, (System.Collections.IEnumerable)ViewData["UserStatus"], "Id", "Status");
columns.Bound(c => c.Status).Title(
"Status"
).HtmlAttributes(
new
{ @
class
=
"lock-col"
}).EditorTemplateName(
"StatusDdl"
).Width(270);
columns.Bound(c => c.Admin).ClientTemplate(
"<input type='checkbox' value='#= Id #' "
+
"# if (Admin) { #"
+
"checked='checked'"
+
"# } #"
+
"/>"
);
where the partialview is used as editor template.
The viewbag however is filled, that I'm sure of, but I think maybe I need to specify a type or something but I can't figure it out.
Regards
Bart
From the code it seems that the ViewBag is populated in the DataSource Read action and not the action used to Render the View with the grid. Thus the ViewBag entry will not be available at the time the grid and its editors are rendered. Please try moving the code to set the ViewBag entry in the action that returns the View with the grid.
Regards,
Daniel
Telerik

thnx,
That's it
User control like this
public
ActionResult Index()
{
ViewData[
"UserStatus"
] = db.UserStatus;
var UserStatus = db.UserStatus.Select(x =>
new
SelectListItem { Value = x.Id.ToString(), Text = x.Status }).ToList();
ViewBag.StatusDdl = UserStatus;
return
View();
}
columns.ForeignKey(c => c.Status, (System.Collections.IEnumerable)ViewData[
"UserStatus"
],
"Id"
,
"Status"
).EditorTemplateName(
"StatusDdl"
).Width(270);