Browse Source

fixed model state filter

tags/v0.1.4
Robin Thoni 7 years ago
parent
commit
c0cf7ca7cf
1 changed files with 7 additions and 4 deletions
  1. 7
    4
      Luticate2.Utils/Middlewares/LuModelStateFilter.cs

+ 7
- 4
Luticate2.Utils/Middlewares/LuModelStateFilter.cs View File

@@ -32,10 +32,13 @@ namespace Luticate2.Utils.Middlewares
32 32
                 var errors = "";
33 33
                 foreach (var key in context.ModelState.Keys)
34 34
                 {
35
-                    var error = " " + key + ": " + context.ModelState[key]
36
-                        .Errors.Select(modelError => modelError.ErrorMessage)
37
-                        .Aggregate((s, s1) => s + ", " + s1);
38
-                    errors += error;
35
+                    var state = context.ModelState[key];
36
+                    if (state.Errors.Count > 0)
37
+                    {
38
+                        var error = " " + key + ": " + state.Errors.Select(modelError => modelError.ErrorMessage)
39
+                                        .Aggregate((s, s1) => s + ", " + s1);
40
+                        errors += error;
41
+                    }
39 42
                 }
40 43
                 throw new LuResultException(LuResult<object>.Error(LuStatus.InputError, "Validation error:" + errors, ""));
41 44
             }

Loading…
Cancel
Save