Sdl.Web.Mvc/Controllers/EntityController.cs
/// <summary>
/// Resolves CM-managed validation messages. 
/// </summary>
/// <param name="inputMessage">The input validation message which may have the special syntax <c>@Model.{$ModelPropertyName}</c>.</param>
/// <param name="model">The View Model used to resolve the value of such Model property expression.</param>
/// <returns>The resolved validation message or the input message in case resolving fails.</returns>
Resolves CM-managed validation messages.
Resolves CM - managed validation messages .
private static string ResolveValidationMessage(string inputMessage, ViewModel model)
        {
            const string modelPrefix = "@Model.";
            if (!inputMessage.StartsWith(modelPrefix))
            {
                return inputMessage;
            }
            string modelPropertyName = inputMessage.Substring(modelPrefix.Length);
            PropertyInfo validationMessageProperty = model.GetType().GetProperty(modelPropertyName);
            string validationMessagePropertyValue = null;
            if (validationMessageProperty != null)
            {
                validationMessagePropertyValue = validationMessageProperty.GetValue(model) as string;
            }
            if (string.IsNullOrEmpty(validationMessagePropertyValue))
            {
                Log.Warn("No validation message could be resolved for expression '{0}'", inputMessage);
                return inputMessage;
            }
            return validationMessagePropertyValue;
        }
private static string ResolveValidationMessage ( string inputMessage , ViewModel model ) { const string modelPrefix = " " ; if ( ! inputMessage . StartsWith ( modelPrefix ) ) { return inputMessage ; } string modelPropertyName = inputMessage . Substring ( modelPrefix . Length ) ; PropertyInfo validationMessageProperty = model . GetType ( ) . GetProperty ( modelPropertyName ) ; string validationMessagePropertyValue = null ; if ( validationMessageProperty != null ) { validationMessagePropertyValue = validationMessageProperty . GetValue ( model ) as string ; } if ( string . IsNullOrEmpty ( validationMessagePropertyValue ) ) { Log . Warn ( " " , inputMessage ) ; return inputMessage ; } return validationMessagePropertyValue ; }
Resolves CM-managed validation messages.
Resolves CM - managed validation messages .
The resolved validation message or the input message in case resolving fails.
The resolved validation message or the input message in case resolving fails .
inputMessage
string
The input validation message which may have the special syntax @Model.{$ModelPropertyName}
The input validation message which may have the special syntax @Model . { $ModelPropertyName }
model
ViewModel
The View Model used to resolve the value of such Model property expression.
The View Model used to resolve the value of such Model property expression .