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

Server binding : how to keep my value an int ?

1 Answer 30 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.
Thomas B
Top achievements
Rank 1
Thomas B asked on 16 Aug 2010, 10:18 AM
Hello

I am new to MVC, and I am trying to use the DropDownList control.
I copy/pasted the example code, like such :

 ViewData["jeux"] = new SelectList(_entities.jeux.ToList(), "jeu_id", "jeu_nom");
<%= Html.Telerik().DropDownList()
                        .Name("jeux")
                        .BindTo((IEnumerable<SelectListItem>)ViewData["jeux"])
                    %>
But on the POST, the returned value is a string, though it should be an int, so the ModelState is not valid.
And I have no idea how to return an int, or convert it to int before validating the ModelState, or whatever.

Thanks for your help

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 16 Aug 2010, 10:57 AM
Hello Broust Thomas,

The posted values to the server is expected to be string. The ASP.NET MVC ModelBinder should get posted value and convert it to the type of the Action parameter. You can check Server validation example locally in order to find out how the ProductDto is bound by ASP.NET MVC framework.

Nevertheless to avoid any misunderstandings I will suggest you implement the same functionality with the Html.DropDownList extension component

Best wishes,
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
Thomas B
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or