Lots of work for validation. We have a different type of validation model in Umbraco where we still save content even if some things are invalid (we just don't publish) so we have to take all of this into account. We also have other rules where if it is new content but required fields like 'name' are empty we cannot continue to save. Also started working on dealing with server side validation errors for content fields (not just user defined fields).

This commit is contained in:
Shannon
2013-07-16 18:23:20 +10:00
parent c7b4cfd375
commit e2fa610358
20 changed files with 564 additions and 281 deletions

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
@@ -46,6 +48,21 @@ namespace Umbraco.Web
// state.AddModelError("DataValidation", errorMessage);
//}
public static IDictionary<string, object> ToErrorDictionary(this System.Web.Http.ModelBinding.ModelStateDictionary modelState)
{
var modelStateError = new Dictionary<string, object>();
foreach (var keyModelStatePair in modelState)
{
var key = keyModelStatePair.Key;
var errors = keyModelStatePair.Value.Errors;
if (errors != null && errors.Count > 0)
{
modelStateError.Add(key, errors.Select(error => error.ErrorMessage));
}
}
return modelStateError;
}
/// <summary>
/// Serializes the ModelState to JSON for JavaScript to interrogate the errors
/// </summary>