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

[Solved] NumericTextBox ModelState

4 Answers 118 Views
NumericTextBox
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stefan
Top achievements
Rank 1
Stefan asked on 29 Jul 2011, 09:30 PM
Hello, i've noticed something unusual.

As far as I know HtmlHelpers are supposed to prefer ModelState-Values over Model-Values (at least on POST's as per http://blogs.msdn.com/b/simonince/archive/2010/05/05/asp-net-mvc-s-html-helpers-render-the-wrong-value.aspx), which at least the CurrencyTextBox does not.

See attached images. I attempt to put in 250, the server does stuff and decides to throw an concurrency exception, I redisplay the form to notify the user about this fact, but the attempted value changes to the Model-Value, even though as per the debugger (locals.png) the ModelState-Value clearly is 250.

If i replace the CurrencyTextBox with a normal one, everything works as expected.

4 Answers, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 01 Aug 2011, 09:46 AM
Hello Stefan,

 
You are absolutely correct. The current implementation does care about the model state, but do not get value from it if the model state is not valid. When the model is not valid then we try to get the component value, which in this case is the model value.
I am glad to inform you that we address this issue and the fix will be available with the next internal build of Telerik Extensions for ASP.NET MVC.

As a gratitude for your involvement I have updated your Telerik points.

Best 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
Karan Misra
Top achievements
Rank 1
answered on 13 Aug 2011, 07:19 AM
So am I correct to assume that all other Telerik Components are also built the same way? I am testing a AutoCompleteFor which is also behaving the same way.

Is this a genuine bug (surprised that it was not spotted till now?) or a mid guided design?
0
Raymond
Top achievements
Rank 1
answered on 19 Aug 2011, 07:59 PM
Thanks for asking this question, I noticed the same thing!

As a follow-up, related question,... any suggestions on how to have the visual display of the Telerik Numeric TextBox highlighted in red?

For regular <input> fields, MVC will add in the class="input-validation-error" -- and then the stylesheets sets the background color to red. All I/we have to do is set an error in the ModelState.

However, when I inspect the HTML element, I see that no such class exists... presumably because Telerik's javascript logic overwrites/renders with its own logic.

Thanks
0
Georgi Krustev
Telerik team
answered on 22 Aug 2011, 09:45 AM
Hello Raymond,

 
In order to achieve your goal you will need to add the error to the ViewData and then in the View use InputHttpAttributes to add "input-validation-error" class to the visible input:

.InputHtmlAttributes(new { @class = ViewData["numeric-errror"] != null ? "input-validaton-error" } : "")

Kind regards,
Georgi Krustev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
NumericTextBox
Asked by
Stefan
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Karan Misra
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Share this question
or