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
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.
Georgi Krustev
the Telerik team
<%= 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.
@Html.Telerik().DropDownList - return Object must implement IConvertible
@Html.Telerik().DropDownListFor - works fine
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.
Georgi Krustev
the Telerik team
<%@ 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?
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".
Georgi Krustev
the Telerik team
My code:
@( Html.Telerik().DropDownList() .Name("AUSStatus") .BindTo(ViewBag.AUSStatus))<%: 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; } } 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