Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Commented Issue: ValidationSummary does not show error message in case of overflow exception [289]

$
0
0
Hi,
I have come across an issue in the ASP.NET MVC3 code.

Steps to recreate issue:
1. Create a variable in your model with type Short (Int16).
2. Create a view for that model
3. Use ValidationSummary to display the validation results in that view.
4. Disable client-side validation
4. Enter a long value(Int32) in the textbox created for the Short(Int16) variable.
5. It will not display any validation message.

I debugged throught he MVC3 source code and have found the following:

File: DefaultModelBinder.cs Line# 213

if(exception is FormatException){
//Copy Exception from Exception to ErrorMessage
}

Whenever a type exception is thrown it is caught by the framework and stored as Exception. The MVC framework code then copies all Exceptions to ErrorMessage as ErrorMessage object is used by ValidationSummary to display any messages. But this happens only if exception is of the type FormatException.

While in the scenario i mentioned above the exception thrown is of the type OverFlow Exception because I am trying to assign a Long Int to Short Int. As the "if" condition is not satisified the Exception is not copied to Errormessage and no message gets displayed on the page.

This will get resolved by modifying the "if" condition as follows:
if(exception is FormatException || exception is OverflowException){
}

Thank you.
Comments: We considered this fix, and unfortunately even if we fix it, you wouldn't get a proper client side validation error. So the suggestion is to add a range property to your model class. It will run properly on the client side, and we are aware this will still do the current thing on the server.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>