Created
September 13, 2014 00:21
-
-
Save xivSolutions/0e41cf6c1c45da1b5bad to your computer and use it in GitHub Desktop.
Deserialize ModelStateDictionary
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original Stack Overflow Answer from http://stackoverflow.com/a/23506548/586518 | |
Original Code from SO answer: | |
```csharp | |
var value = await response.Content.ReadAsStringAsync(); | |
if (!response.IsSuccessStatusCode) | |
{ | |
var obj = new { message = "", ModelState = new Dictionary<string,string[]>() }; | |
var x = JsonConvert.DeserializeAnonymousType(value, obj); | |
throw new AggregateException(x.ModelState.Select(kvp => new Exception(string.Format("{0}: {1}", kvp.Key, string.Join(". ", kvp.Value))))); | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment