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

[Solved] How to bind the selected item of the comboBox to my model?

5 Answers 272 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.
Julien
Top achievements
Rank 1
Julien asked on 02 Feb 2012, 03:29 PM
Hi,

I'm using for the first time telerik for my asp.net mvc forms.

I've a question about how to bind it to my model.

I've no problem to bind the comboBox to the list which contains all values, but I can't find how I can bind the selected id to one property of my model.

In camparison, with the dropDownList , I was using the 
@Html.DropDownListFor(x=>x.MyProperty, ...)

But here I can't find any method like this, what is the correct way?

5 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 03 Feb 2012, 09:20 AM
Hello Julien,

 
I will suggest you use:

@Html.Telerik().DropDownListFor(x=>x.MyProperty)
This will get the value of the MyProperty and will set the selected item.

Regards,
Georgi Krustev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Julien
Top achievements
Rank 1
answered on 08 Feb 2012, 03:38 PM
Okay, but this will generate me only a dropdown list no? I need to have the comboBox like it works here http://demos.telerik.com/aspnet-mvc/combobox 

And I can't see how to specify which values can be used in the combo box
0
Georgi Krustev
Telerik team
answered on 09 Feb 2012, 09:50 AM
Hello Julien,

 
In that case you will need to use ComboBoxFor:

@(Html.Telerik().ComboBoxFor(x=>x.MyProperty)
      .BindTo(data)
)


Regards,
Georgi Krustev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Le
Top achievements
Rank 1
answered on 21 Jun 2012, 09:38 AM
Thanks so much,
0
Andy
Top achievements
Rank 1
answered on 03 Aug 2012, 06:56 PM
Hi Georgi,
 
Your snippet works only so long as the control does not have a name. However, if you specify a control name, it appears to stop working:
@(Html.Telerik().ComboBoxFor(x=>x.MyProperty)
       .Name("myName")
       .BindTo(data)
 )

Any suggestions?
Tags
ComboBox
Asked by
Julien
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Julien
Top achievements
Rank 1
Le
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Share this question
or