This is a migrated thread and some comments may be shown as answers.

[Solved] Can't bind a DrowDownList due to Object must implement IConvertible

12 Answers 304 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
dani
Top achievements
Rank 1
dani asked on 22 Jan 2011, 08:39 PM
I'm trying to show a DropDownList and I keep getting this exception:
Object must implement IConvertible

<%= Html.Telerik().DropDownList().Name("orders")
        .BindTo(Model.Orders)%>

when Model.Orders is generated using

myOrders.Select(x => new SelectListItem
            {  
                Value = x.OrderID.ToString(),
                Text = x.OrderName + "some text"
                Selected = x.OrderID = OrderID
}).ToList();

What am I doing wrong?
Thanks, Dani

12 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 24 Jan 2011, 09:49 AM
Hello Dani,

I have created a simple test project in my attempt to reproduce the depicted issue, but to no avail. The project is attached to this message.

All the best,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
dani
Top achievements
Rank 1
answered on 24 Jan 2011, 10:00 AM
Thanks, It does work, and it's the same code, I'll keep looking for the problem, and post here if I'll find it.
0
montgomery
Top achievements
Rank 1
answered on 24 Jan 2011, 09:34 PM
FYI, I get the same error on our combo boxes after upgrading to 2010.3.1318.235. Our combo box is stored in a DisplayTemplate control and uses a SelectList stored in ViewData. I will also post a solution if I find one. The sample project in the second post also worked for me.
0
montgomery
Top achievements
Rank 1
answered on 24 Jan 2011, 09:49 PM
The issue is caused by the following code:

<%= Html.Telerik()
    .ComboBox()
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
    //.Name(Guid.NewGuid().ToString())
    .BindTo(ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)] as SelectList)
    .AutoFill(true)
    .HighlightFirstMatch(true)
    .Filterable(filtering => { filtering.FilterMode(AutoCompleteFilterMode.Contains);})                                
%>

If I use the line that uses a random Guid as the Name property it works. If I use the ViewData to pull the field name then I get the error displayed in the first post of this thread. If I'm using the ComboBox() in a shared DisplayTemplates control, is there a better way to populate a dynamic name for the Name property? This control is tagged as a ComboBox type in the model and called via Html.EditorFor.
0
Jakub
Top achievements
Rank 1
answered on 26 Jan 2011, 02:43 PM
Hi,

@Html.Telerik().DropDownList - return Object must implement IConvertible
@Html.Telerik().DropDownListFor - works fine
0
Georgi Krustev
Telerik team
answered on 26 Jan 2011, 06:15 PM
Hello,

 We were able to observe this issue locally and I am glad to inform that it is already fixed.
The fix will be included in the next official release of Telerik components for ASP.NET MVC. Also this fix will be available for customers as an internal build.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rafael
Top achievements
Rank 1
answered on 28 Jan 2011, 11:33 AM
With v2010.3.1110 I used for field in grid  

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.Telerik().DropDownList().Name("RateMode").BindTo(new SelectList((IEnumerable)ViewData["RateMode"], "RateValue", "RateName"))
%>

With  v2010.3.1318 it dowsn't work due to IConvertible.
But I can't use DropDownListFor as well cause model isn't binding 

What I am missing?
Could you provide some workaround or link to internal build please?
0
Georgi Krustev
Telerik team
answered on 28 Jan 2011, 01:13 PM
Hello Rafael,

 
This is a known issue, which is already fixed. ComboBox will throw an exception if it is named to a ViewData key, which does not return string while evaluating ViewData. I will suggest you use another key value for the IEnumerable collection. For instance "RateModeCollection".

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rafael
Top achievements
Rank 1
answered on 28 Jan 2011, 01:56 PM
Man, you brought me back to life: thanks so much, Georgi
0
Luis
Top achievements
Rank 1
answered on 04 Feb 2011, 06:20 PM
I am getting the same error, tried looking for the internal build fix but couldn't find it. Can anyone point me to the right direction. 
My code:
@(     Html.Telerik().DropDownList()
       .Name("AUSStatus")
       .BindTo(ViewBag.AUSStatus)
 
)
0
Ronald
Top achievements
Rank 1
answered on 10 Feb 2011, 02:06 PM
I'm using Telerik.Web.Mvc.dll v2010.3.1324.235 (latest internal build) and have the same issue with following code. Previous version (v 2010.3.1110.235) did not have this issue

<%: Html.Telerik().DropDownListFor(m => m.Ratio.Positions)
.ClientEvents(e => e.OnChange("loadPartialView"))
.BindTo(new SelectList(ViewData["RatioPositions"] as IEnumerable, "Id", "Name"))
.HtmlAttributes(new { style = "width: 30px"})
.Effects(effects => effects.Expand())
.DropDownHtmlAttributes(new { style = "width: 100px" })
%>

With ViewData["RatioPositions"] set to an IList<RatioPosition>

ViewData["RatioPositions"] = ratioPositionRepository.GetAll().OrderBy(p => p.Name);
  
public class RatioPosition
{
 public int Id {get; set;}
 public string Name { get; set; }
}
0
Georgi Krustev
Telerik team
answered on 11 Feb 2011, 09:55 AM
Hello Ronald,

 Version 2010.3.1324 does not include the fix of the reported issue. I have uploaded new internal build (version 2010.3.1410), you can download it from your account and review release notes.

Regards,
Georgi Krustev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
ComboBox
Asked by
dani
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
dani
Top achievements
Rank 1
montgomery
Top achievements
Rank 1
Jakub
Top achievements
Rank 1
Rafael
Top achievements
Rank 1
Luis
Top achievements
Rank 1
Ronald
Top achievements
Rank 1
Share this question
or