This is a migrated thread and some comments may be shown as answers.
Autocomplete default value
4 Answers 105 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jann
Top achievements
Rank 1
Jann asked on 25 Jan 2011, 12:07 AM
I have a editor template that looks like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<%
    IEnumerable<string> lCodes;
    if (ViewData[FactorStrings.ExchangeCodes] is IEnumerable<string>)
    {
        lCodes = (IEnumerable<string>)ViewData[FactorStrings.Codes];
    }
    else
    {
        lCodes = new List<string> { Model };
    }
%>
<%= Html.Telerik().AutoComplete()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .BindTo(lCodes)%>

My problem is that the control does not display the value (i.e. Model). This is somehow understandable since I don't tell it anywhere which value to display, but I also don't see an obvious way to do it (like .Value("something")) Is this a bug? I don't really want to do a hack like adding a html attribute with "value = Model" to show the value.

PS: Using AutoCompleteFor(...) directly in a view shows the value just fine.

4 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 25 Jan 2011, 09:57 AM
Hello Jann,

In order to get value from model and display it in AutoComplete UI component you need to use this code snippet:

<%= Html.Telerik().AutoCompleteFor(m => m)
        .BindTo(...)
 %>

Actually this it the way how you should use a regular Html.TextBox() component. It will not show the Model value if you set its name with ViewData.TemplateInfo.GetFullHtmlFieldName("").

Greetings,
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
Jann
Top achievements
Rank 1
answered on 25 Jan 2011, 12:28 PM
This does not work in an editor template. The string editor template from microsoft looks like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
<%= Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "text-box single-line" }) %>

So I guess the autocomplete control needs a way to pass in the value to display.
0
Accepted
Georgi Krustev
Telerik team
answered on 25 Jan 2011, 12:43 PM
Hello Jann,

 
I have attached a simple test project which shows how to achieve your goal.

Kind 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
Jann
Top achievements
Rank 1
answered on 25 Jan 2011, 04:39 PM
Ok, it works with the version you use. The release version is broken in that respect.

But thanks for providing me with the new version this fixed my problem.
Tags
ComboBox
Asked by
Jann
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Jann
Top achievements
Rank 1
Share this question
or