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

Created Unassigned: [Regression]: Unexpected validationError thrown when required property value is not set [1470]

$
0
0
Here is my model
[DataContract]
public class ValidationModel
{
[Required]
[DataMember]
[Range(1, 10)]
public int IntReq { get; set; }

[Required]
[DataMember]
[StringLength(5)]
public string StrReq { get; set; }
}

My Post action on service returns model state errors (code below at the end). When I call a post on client with following data
var model = "{\"StrReq\":\"foo\"}";

I see 2 errors on 5.1
__Exception:Required property 'IntReq' not found in JSON. Path '', line 1, position 16.
The field IntReq must be between 1 and 10.__

For 2013 preview build, I just see 1 error - Exception:Required property 'IntReq' not found in JSON. Path '', line 1, position 16.

Post Code on server side

public List<KeyValuePair<string, string[]>> PostValidationModel(ValidationModel model)
{
var modelErrors = new List<KeyValuePair<string, string[]>>();
foreach (var key in ModelState.Keys)
{
var errors = new List<string>();
foreach (var e in ModelState[key].Errors)
{
var errorMsg = !String.IsNullOrWhiteSpace(e.ErrorMessage) ? e.ErrorMessage :
e.Exception != null ? "Exception:" + e.Exception.Message : String.Empty;
errors.Add(errorMsg);
}
modelErrors.Add(new KeyValuePair<string, string[]>(key, errors.ToArray()));
}
return modelErrors;
}


Viewing all articles
Browse latest Browse all 7215

Trending Articles



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