Rename ModelState (the type) -> ModelStateEntry

Fixes #3326
This commit is contained in:
Pranav K 2015-10-20 12:19:36 -07:00
parent 173f00fda7
commit 8b0c157296
19 changed files with 268 additions and 263 deletions

View File

@ -6,7 +6,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <summary> /// <summary>
/// An entry in a <see cref="ModelStateDictionary"/>. /// An entry in a <see cref="ModelStateDictionary"/>.
/// </summary> /// </summary>
public class ModelState public class ModelStateEntry
{ {
/// <summary> /// <summary>
/// Gets the raw value from the request associated with this entry. /// Gets the raw value from the request associated with this entry.

View File

@ -12,7 +12,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// Represents the state of an attempt to bind values from an HTTP Request to an action method, which includes /// Represents the state of an attempt to bind values from an HTTP Request to an action method, which includes
/// validation information. /// validation information.
/// </summary> /// </summary>
public class ModelStateDictionary : IDictionary<string, ModelState> public class ModelStateDictionary : IDictionary<string, ModelStateEntry>
{ {
// Make sure to update the doc headers if this value is changed. // Make sure to update the doc headers if this value is changed.
/// <summary> /// <summary>
@ -20,7 +20,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// </summary> /// </summary>
public static readonly int DefaultMaxAllowedErrors = 200; public static readonly int DefaultMaxAllowedErrors = 200;
private readonly Dictionary<string, ModelState> _innerDictionary; private readonly Dictionary<string, ModelStateEntry> _innerDictionary;
private int _maxAllowedErrors; private int _maxAllowedErrors;
/// <summary> /// <summary>
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
MaxAllowedErrors = maxAllowedErrors; MaxAllowedErrors = maxAllowedErrors;
_innerDictionary = new Dictionary<string, ModelState>(StringComparer.OrdinalIgnoreCase); _innerDictionary = new Dictionary<string, ModelStateEntry>(StringComparer.OrdinalIgnoreCase);
} }
/// <summary> /// <summary>
@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(dictionary)); throw new ArgumentNullException(nameof(dictionary));
} }
_innerDictionary = new Dictionary<string, ModelState>( _innerDictionary = new Dictionary<string, ModelStateEntry>(
dictionary, dictionary,
StringComparer.OrdinalIgnoreCase); StringComparer.OrdinalIgnoreCase);
@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// the error message will be ignored and a <see cref="TooManyModelErrorsException"/> will be added. /// the error message will be ignored and a <see cref="TooManyModelErrorsException"/> will be added.
/// </para> /// </para>
/// <para> /// <para>
/// Errors added via modifying <see cref="ModelState"/> directly do not count towards this limit. /// Errors added via modifying <see cref="ModelStateEntry"/> directly do not count towards this limit.
/// </para> /// </para>
/// </remarks> /// </remarks>
public int MaxAllowedErrors public int MaxAllowedErrors
@ -122,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <inheritdoc /> /// <inheritdoc />
public bool IsReadOnly public bool IsReadOnly
{ {
get { return ((ICollection<KeyValuePair<string, ModelState>>)_innerDictionary).IsReadOnly; } get { return ((ICollection<KeyValuePair<string, ModelStateEntry>>)_innerDictionary).IsReadOnly; }
} }
/// <inheritdoc /> /// <inheritdoc />
@ -132,7 +132,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public ICollection<ModelState> Values public ICollection<ModelStateEntry> Values
{ {
get { return _innerDictionary.Values; } get { return _innerDictionary.Values; }
} }
@ -159,7 +159,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public ModelState this[string key] public ModelStateEntry this[string key]
{ {
get get
{ {
@ -168,7 +168,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(key)); throw new ArgumentNullException(nameof(key));
} }
ModelState value; ModelStateEntry value;
_innerDictionary.TryGetValue(key, out value); _innerDictionary.TryGetValue(key, out value);
return value; return value;
} }
@ -188,7 +188,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
// For unit testing // For unit testing
internal IDictionary<string, ModelState> InnerDictionary internal IDictionary<string, ModelStateEntry> InnerDictionary
{ {
get { return _innerDictionary; } get { return _innerDictionary; }
} }
@ -197,10 +197,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
private bool HasRecordedMaxModelError { get; set; } private bool HasRecordedMaxModelError { get; set; }
/// <summary> /// <summary>
/// Adds the specified <paramref name="exception"/> to the <see cref="ModelState.Errors"/> instance /// Adds the specified <paramref name="exception"/> to the <see cref="ModelStateEntry.Errors"/> instance
/// that is associated with the specified <paramref name="key"/>. /// that is associated with the specified <paramref name="key"/>.
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to add errors to.</param> /// <param name="key">The key of the <see cref="ModelStateEntry"/> to add errors to.</param>
/// <param name="exception">The <see cref="Exception"/> to add.</param> /// <param name="exception">The <see cref="Exception"/> to add.</param>
public void AddModelError(string key, Exception exception) public void AddModelError(string key, Exception exception)
{ {
@ -218,11 +218,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <summary> /// <summary>
/// Attempts to add the specified <paramref name="exception"/> to the <see cref="ModelState.Errors"/> /// Attempts to add the specified <paramref name="exception"/> to the <see cref="ModelStateEntry.Errors"/>
/// instance that is associated with the specified <paramref name="key"/>. If the maximum number of allowed /// instance that is associated with the specified <paramref name="key"/>. If the maximum number of allowed
/// errors has already been recorded, records a <see cref="TooManyModelErrorsException"/> exception instead. /// errors has already been recorded, records a <see cref="TooManyModelErrorsException"/> exception instead.
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to add errors to.</param> /// <param name="key">The key of the <see cref="ModelStateEntry"/> to add errors to.</param>
/// <param name="exception">The <see cref="Exception"/> to add.</param> /// <param name="exception">The <see cref="Exception"/> to add.</param>
/// <returns> /// <returns>
/// <c>True</c> if the given error was added, <c>false</c> if the error was ignored. /// <c>True</c> if the given error was added, <c>false</c> if the error was ignored.
@ -249,18 +249,18 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
if (exception is FormatException || exception is OverflowException) if (exception is FormatException || exception is OverflowException)
{ {
// Convert FormatExceptions and OverflowExceptions to Invalid value messages. // Convert FormatExceptions and OverflowExceptions to Invalid value messages.
ModelState modelState; ModelStateEntry entry;
TryGetValue(key, out modelState); TryGetValue(key, out entry);
string errorMessage; string errorMessage;
if (modelState == null) if (entry == null)
{ {
errorMessage = Resources.FormatModelError_InvalidValue_GenericMessage(key); errorMessage = Resources.FormatModelError_InvalidValue_GenericMessage(key);
} }
else else
{ {
errorMessage = Resources.FormatModelError_InvalidValue_MessageWithModelValue( errorMessage = Resources.FormatModelError_InvalidValue_MessageWithModelValue(
modelState.AttemptedValue, entry.AttemptedValue,
key); key);
} }
@ -273,10 +273,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <summary> /// <summary>
/// Adds the specified <paramref name="errorMessage"/> to the <see cref="ModelState.Errors"/> instance /// Adds the specified <paramref name="errorMessage"/> to the <see cref="ModelStateEntry.Errors"/> instance
/// that is associated with the specified <paramref name="key"/>. /// that is associated with the specified <paramref name="key"/>.
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to add errors to.</param> /// <param name="key">The key of the <see cref="ModelStateEntry"/> to add errors to.</param>
/// <param name="errorMessage">The error message to add.</param> /// <param name="errorMessage">The error message to add.</param>
public void AddModelError(string key, string errorMessage) public void AddModelError(string key, string errorMessage)
{ {
@ -294,11 +294,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <summary> /// <summary>
/// Attempts to add the specified <paramref name="errorMessage"/> to the <see cref="ModelState.Errors"/> /// Attempts to add the specified <paramref name="errorMessage"/> to the <see cref="ModelStateEntry.Errors"/>
/// instance that is associated with the specified <paramref name="key"/>. If the maximum number of allowed /// instance that is associated with the specified <paramref name="key"/>. If the maximum number of allowed
/// errors has already been recorded, records a <see cref="TooManyModelErrorsException"/> exception instead. /// errors has already been recorded, records a <see cref="TooManyModelErrorsException"/> exception instead.
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to add errors to.</param> /// <param name="key">The key of the <see cref="ModelStateEntry"/> to add errors to.</param>
/// <param name="errorMessage">The error message to add.</param> /// <param name="errorMessage">The error message to add.</param>
/// <returns> /// <returns>
/// <c>True</c> if the given error was added, <c>false</c> if the error was ignored. /// <c>True</c> if the given error was added, <c>false</c> if the error was ignored.
@ -363,7 +363,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
throw new ArgumentNullException(nameof(key)); throw new ArgumentNullException(nameof(key));
} }
ModelState validationState; ModelStateEntry validationState;
if (TryGetValue(key, out validationState)) if (TryGetValue(key, out validationState))
{ {
return validationState.ValidationState; return validationState.ValidationState;
@ -373,10 +373,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <summary> /// <summary>
/// Marks the <see cref="ModelState.ValidationState"/> for the entry with the specified <paramref name="key"/> /// Marks the <see cref="ModelStateEntry.ValidationState"/> for the entry with the specified
/// as <see cref="ModelValidationState.Valid"/>. /// <paramref name="key"/> as <see cref="ModelValidationState.Valid"/>.
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to mark as valid.</param> /// <param name="key">The key of the <see cref="ModelStateEntry"/> to mark as valid.</param>
public void MarkFieldValid(string key) public void MarkFieldValid(string key)
{ {
if (key == null) if (key == null)
@ -394,10 +394,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <summary> /// <summary>
/// Marks the <see cref="ModelState.ValidationState"/> for the entry with the specified <paramref name="key"/> /// Marks the <see cref="ModelStateEntry.ValidationState"/> for the entry with the specified <paramref name="key"/>
/// as <see cref="ModelValidationState.Skipped"/>. /// as <see cref="ModelValidationState.Skipped"/>.
/// </summary> /// </summary>
/// <param name="key">The key of the <see cref="ModelState"/> to mark as skipped.</param> /// <param name="key">The key of the <see cref="ModelStateEntry"/> to mark as skipped.</param>
public void MarkFieldSkipped(string key) public void MarkFieldSkipped(string key)
{ {
if (key == null) if (key == null)
@ -433,11 +433,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <summary> /// <summary>
/// Sets the of <see cref="ModelState.RawValue"/> and <see cref="ModelState.AttemptedValue"/> for /// Sets the of <see cref="ModelStateEntry.RawValue"/> and <see cref="ModelStateEntry.AttemptedValue"/> for
/// the <see cref="ModelState"/> with the specified <paramref name="key"/>. /// the <see cref="ModelStateEntry"/> with the specified <paramref name="key"/>.
/// </summary> /// </summary>
/// <param name="key">The key for the <see cref="ModelState"/> entry.</param> /// <param name="key">The key for the <see cref="ModelStateEntry"/> entry.</param>
/// <param name="rawvalue">The raw value for the <see cref="ModelState"/> entry.</param> /// <param name="rawvalue">The raw value for the <see cref="ModelStateEntry"/> entry.</param>
/// <param name="attemptedValue"> /// <param name="attemptedValue">
/// The values of <param name="rawValue"/> in a comma-separated <see cref="string"/>. /// The values of <param name="rawValue"/> in a comma-separated <see cref="string"/>.
/// </param> /// </param>
@ -454,11 +454,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <summary> /// <summary>
/// Sets the value for the <see cref="ModelState"/> with the specified <paramref name="key"/>. /// Sets the value for the <see cref="ModelStateEntry"/> with the specified <paramref name="key"/>.
/// </summary> /// </summary>
/// <param name="key">The key for the <see cref="ModelState"/> entry</param> /// <param name="key">The key for the <see cref="ModelStateEntry"/> entry</param>
/// <param name="valueProviderResult"> /// <param name="valueProviderResult">
/// A <see cref="ValueProviderResult"/> with data for the <see cref="ModelState"/> entry. /// A <see cref="ValueProviderResult"/> with data for the <see cref="ModelStateEntry"/> entry.
/// </param> /// </param>
public void SetModelValue(string key, ValueProviderResult valueProviderResult) public void SetModelValue(string key, ValueProviderResult valueProviderResult)
{ {
@ -501,21 +501,21 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
} }
private ModelState GetModelStateForKey(string key) private ModelStateEntry GetModelStateForKey(string key)
{ {
if (key == null) if (key == null)
{ {
throw new ArgumentNullException(nameof(key)); throw new ArgumentNullException(nameof(key));
} }
ModelState modelState; ModelStateEntry entry;
if (!TryGetValue(key, out modelState)) if (!TryGetValue(key, out entry))
{ {
modelState = new ModelState(); entry = new ModelStateEntry();
this[key] = modelState; this[key] = entry;
} }
return modelState; return entry;
} }
private static ModelValidationState GetValidity(PrefixEnumerable entries, ModelValidationState defaultState) private static ModelValidationState GetValidity(PrefixEnumerable entries, ModelValidationState defaultState)
@ -562,13 +562,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public void Add(KeyValuePair<string, ModelState> item) public void Add(KeyValuePair<string, ModelStateEntry> item)
{ {
Add(item.Key, item.Value); Add(item.Key, item.Value);
} }
/// <inheritdoc /> /// <inheritdoc />
public void Add(string key, ModelState value) public void Add(string key, ModelStateEntry value)
{ {
if (key == null) if (key == null)
{ {
@ -590,9 +590,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public bool Contains(KeyValuePair<string, ModelState> item) public bool Contains(KeyValuePair<string, ModelStateEntry> item)
{ {
return ((ICollection<KeyValuePair<string, ModelState>>)_innerDictionary).Contains(item); return ((ICollection<KeyValuePair<string, ModelStateEntry>>)_innerDictionary).Contains(item);
} }
/// <inheritdoc /> /// <inheritdoc />
@ -607,20 +607,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public void CopyTo(KeyValuePair<string, ModelState>[] array, int arrayIndex) public void CopyTo(KeyValuePair<string, ModelStateEntry>[] array, int arrayIndex)
{ {
if (array == null) if (array == null)
{ {
throw new ArgumentNullException(nameof(array)); throw new ArgumentNullException(nameof(array));
} }
((ICollection<KeyValuePair<string, ModelState>>)_innerDictionary).CopyTo(array, arrayIndex); ((ICollection<KeyValuePair<string, ModelStateEntry>>)_innerDictionary).CopyTo(array, arrayIndex);
} }
/// <inheritdoc /> /// <inheritdoc />
public bool Remove(KeyValuePair<string, ModelState> item) public bool Remove(KeyValuePair<string, ModelStateEntry> item)
{ {
return ((ICollection<KeyValuePair<string, ModelState>>)_innerDictionary).Remove(item); return ((ICollection<KeyValuePair<string, ModelStateEntry>>)_innerDictionary).Remove(item);
} }
/// <inheritdoc /> /// <inheritdoc />
@ -635,7 +635,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public bool TryGetValue(string key, out ModelState value) public bool TryGetValue(string key, out ModelStateEntry value)
{ {
if (key == null) if (key == null)
{ {
@ -646,7 +646,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public IEnumerator<KeyValuePair<string, ModelState>> GetEnumerator() public IEnumerator<KeyValuePair<string, ModelStateEntry>> GetEnumerator()
{ {
return _innerDictionary.GetEnumerator(); return _innerDictionary.GetEnumerator();
} }
@ -732,7 +732,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return new PrefixEnumerable(this, prefix); return new PrefixEnumerable(this, prefix);
} }
public struct PrefixEnumerable : IEnumerable<KeyValuePair<string, ModelState>> public struct PrefixEnumerable : IEnumerable<KeyValuePair<string, ModelStateEntry>>
{ {
private readonly ModelStateDictionary _dictionary; private readonly ModelStateDictionary _dictionary;
private readonly string _prefix; private readonly string _prefix;
@ -758,7 +758,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
return _dictionary == null ? new PrefixEnumerator() : new PrefixEnumerator(_dictionary, _prefix); return _dictionary == null ? new PrefixEnumerator() : new PrefixEnumerator(_dictionary, _prefix);
} }
IEnumerator<KeyValuePair<string, ModelState>> IEnumerable<KeyValuePair<string, ModelState>>.GetEnumerator() IEnumerator<KeyValuePair<string, ModelStateEntry>>
IEnumerable<KeyValuePair<string, ModelStateEntry>>.GetEnumerator()
{ {
return GetEnumerator(); return GetEnumerator();
} }
@ -769,13 +770,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
} }
public struct PrefixEnumerator : IEnumerator<KeyValuePair<string, ModelState>> public struct PrefixEnumerator : IEnumerator<KeyValuePair<string, ModelStateEntry>>
{ {
private readonly ModelStateDictionary _dictionary; private readonly ModelStateDictionary _dictionary;
private readonly string _prefix; private readonly string _prefix;
private bool _exactMatchUsed; private bool _exactMatchUsed;
private Dictionary<string, ModelState>.Enumerator _enumerator; private Dictionary<string, ModelStateEntry>.Enumerator _enumerator;
public PrefixEnumerator(ModelStateDictionary dictionary, string prefix) public PrefixEnumerator(ModelStateDictionary dictionary, string prefix)
{ {
@ -793,11 +794,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
_prefix = prefix; _prefix = prefix;
_exactMatchUsed = false; _exactMatchUsed = false;
_enumerator = default(Dictionary<string, ModelState>.Enumerator); _enumerator = default(Dictionary<string, ModelStateEntry>.Enumerator);
Current = default(KeyValuePair<string, ModelState>); Current = default(KeyValuePair<string, ModelStateEntry>);
} }
public KeyValuePair<string, ModelState> Current { get; private set; } public KeyValuePair<string, ModelStateEntry> Current { get; private set; }
object IEnumerator.Current object IEnumerator.Current
{ {
@ -826,10 +827,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
_exactMatchUsed = true; _exactMatchUsed = true;
_enumerator = _dictionary._innerDictionary.GetEnumerator(); _enumerator = _dictionary._innerDictionary.GetEnumerator();
ModelState entry; ModelStateEntry entry;
if (_dictionary.TryGetValue(_prefix, out entry)) if (_dictionary.TryGetValue(_prefix, out entry))
{ {
Current = new KeyValuePair<string, ModelState>(_prefix, entry); Current = new KeyValuePair<string, ModelStateEntry>(_prefix, entry);
return true; return true;
} }
} }
@ -853,8 +854,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void Reset() public void Reset()
{ {
_exactMatchUsed = false; _exactMatchUsed = false;
_enumerator = default(Dictionary<string, ModelState>.Enumerator); _enumerator = default(Dictionary<string, ModelStateEntry>.Enumerator);
Current = default(KeyValuePair<string, ModelState>); Current = default(KeyValuePair<string, ModelStateEntry>);
} }
} }
} }

View File

@ -26,7 +26,7 @@ namespace Microsoft.AspNet.Mvc
/// <summary> /// <summary>
/// Creates a new instance of <see cref="SerializableError"/>. /// Creates a new instance of <see cref="SerializableError"/>.
/// </summary> /// </summary>
/// <param name="modelState"><see cref="ModelState"/> containing the validation errors.</param> /// <param name="modelState"><see cref="ModelStateEntry"/> containing the validation errors.</param>
public SerializableError(ModelStateDictionary modelState) public SerializableError(ModelStateDictionary modelState)
: this() : this()
{ {

View File

@ -10,30 +10,30 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
{ {
internal static class ValidationHelpers internal static class ValidationHelpers
{ {
public static string GetUserErrorMessageOrDefault(ModelError modelError, ModelState modelState) public static string GetUserErrorMessageOrDefault(ModelError modelError, ModelStateEntry entry)
{ {
if (!string.IsNullOrEmpty(modelError.ErrorMessage)) if (!string.IsNullOrEmpty(modelError.ErrorMessage))
{ {
return modelError.ErrorMessage; return modelError.ErrorMessage;
} }
if (modelState == null) if (entry == null)
{ {
return string.Empty; return string.Empty;
} }
var attemptedValue = modelState.AttemptedValue ?? "null"; var attemptedValue = entry.AttemptedValue ?? "null";
return Resources.FormatCommon_ValueNotValidForProperty(attemptedValue); return Resources.FormatCommon_ValueNotValidForProperty(attemptedValue);
} }
// Returns non-null list of model states, which caller will render in order provided. // Returns non-null list of model states, which caller will render in order provided.
public static IEnumerable<ModelState> GetModelStateList( public static IEnumerable<ModelStateEntry> GetModelStateList(
ViewDataDictionary viewData, ViewDataDictionary viewData,
bool excludePropertyErrors) bool excludePropertyErrors)
{ {
if (excludePropertyErrors) if (excludePropertyErrors)
{ {
ModelState ms; ModelStateEntry ms;
viewData.ModelState.TryGetValue(viewData.TemplateInfo.HtmlFieldPrefix, out ms); viewData.ModelState.TryGetValue(viewData.TemplateInfo.HtmlFieldPrefix, out ms);
if (ms != null) if (ms != null)
@ -41,7 +41,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
return new[] { ms }; return new[] { ms };
} }
return Enumerable.Empty<ModelState>(); return Enumerable.Empty<ModelStateEntry>();
} }
else else
{ {
@ -58,7 +58,8 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal
// ModelState doesn't refer to ModelMetadata, but we can correlate via the property name. // ModelState doesn't refer to ModelMetadata, but we can correlate via the property name.
private class ErrorsOrderer private class ErrorsOrderer
{ {
private Dictionary<string, int> _ordering = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase); private readonly Dictionary<string, int> _ordering =
new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
public ErrorsOrderer(ModelMetadata metadata) public ErrorsOrderer(ModelMetadata metadata)
{ {

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public static class ModelStateDictionaryExtensions public static class ModelStateDictionaryExtensions
{ {
/// <summary> /// <summary>
/// Adds the specified <paramref name="errorMessage"/> to the <see cref="ModelState.Errors"/> instance /// Adds the specified <paramref name="errorMessage"/> to the <see cref="ModelStateEntry.Errors"/> instance
/// that is associated with the specified <paramref name="expression"/>. /// that is associated with the specified <paramref name="expression"/>.
/// </summary> /// </summary>
/// <typeparam name="TModel">The type of the model.</typeparam> /// <typeparam name="TModel">The type of the model.</typeparam>
@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <summary> /// <summary>
/// Adds the specified <paramref name="exception"/> to the <see cref="ModelState.Errors"/> instance /// Adds the specified <paramref name="exception"/> to the <see cref="ModelStateEntry.Errors"/> instance
/// that is associated with the specified <paramref name="expression"/>. /// that is associated with the specified <paramref name="expression"/>.
/// </summary> /// </summary>
/// <typeparam name="TModel">The type of the model.</typeparam> /// <typeparam name="TModel">The type of the model.</typeparam>

View File

@ -546,10 +546,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
} }
// If there are any errors for a named field, we add the css attribute. // If there are any errors for a named field, we add the css attribute.
ModelState modelState; ModelStateEntry entry;
if (viewContext.ViewData.ModelState.TryGetValue(fullName, out modelState)) if (viewContext.ViewData.ModelState.TryGetValue(fullName, out entry))
{ {
if (modelState.Errors.Count > 0) if (entry.Errors.Count > 0)
{ {
tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName); tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);
} }
@ -599,13 +599,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
nameof(expression)); nameof(expression));
} }
ModelState modelState; ModelStateEntry entry;
viewContext.ViewData.ModelState.TryGetValue(fullName, out modelState); viewContext.ViewData.ModelState.TryGetValue(fullName, out entry);
var value = string.Empty; var value = string.Empty;
if (modelState != null && modelState.AttemptedValue != null) if (entry != null && entry.AttemptedValue != null)
{ {
value = modelState.AttemptedValue; value = entry.AttemptedValue;
} }
else if (modelExplorer.Model != null) else if (modelExplorer.Model != null)
{ {
@ -629,7 +629,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
tagBuilder.MergeAttributes(GetValidationAttributes(viewContext, modelExplorer, expression)); tagBuilder.MergeAttributes(GetValidationAttributes(viewContext, modelExplorer, expression));
// If there are any errors for a named field, we add this CSS attribute. // If there are any errors for a named field, we add this CSS attribute.
if (modelState != null && modelState.Errors.Count > 0) if (entry != null && entry.Errors.Count > 0)
{ {
tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName); tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);
} }
@ -703,9 +703,9 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
return null; return null;
} }
ModelState modelState; ModelStateEntry entry;
var tryGetModelStateResult = viewContext.ViewData.ModelState.TryGetValue(fullName, out modelState); var tryGetModelStateResult = viewContext.ViewData.ModelState.TryGetValue(fullName, out entry);
var modelErrors = tryGetModelStateResult ? modelState.Errors : null; var modelErrors = tryGetModelStateResult ? entry.Errors : null;
ModelError modelError = null; ModelError modelError = null;
if (modelErrors != null && modelErrors.Count != 0) if (modelErrors != null && modelErrors.Count != 0)
@ -741,7 +741,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
else if (modelError != null) else if (modelError != null)
{ {
tagBuilder.InnerHtml.SetContent( tagBuilder.InnerHtml.SetContent(
ValidationHelpers.GetUserErrorMessageOrDefault(modelError, modelState)); ValidationHelpers.GetUserErrorMessageOrDefault(modelError, entry));
} }
if (formContext != null) if (formContext != null)
@ -804,7 +804,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
for (var i = 0; i < modelState.Errors.Count; i++) for (var i = 0; i < modelState.Errors.Count; i++)
{ {
var modelError = modelState.Errors[i]; var modelError = modelState.Errors[i];
var errorText = ValidationHelpers.GetUserErrorMessageOrDefault(modelError, modelState: null); var errorText = ValidationHelpers.GetUserErrorMessageOrDefault(modelError, entry: null);
if (!string.IsNullOrEmpty(errorText)) if (!string.IsNullOrEmpty(errorText))
{ {
@ -1056,10 +1056,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
internal static object GetModelStateValue(ViewContext viewContext, string key, Type destinationType) internal static object GetModelStateValue(ViewContext viewContext, string key, Type destinationType)
{ {
ModelState modelState; ModelStateEntry entry;
if (viewContext.ViewData.ModelState.TryGetValue(key, out modelState) && modelState.RawValue != null) if (viewContext.ViewData.ModelState.TryGetValue(key, out entry) && entry.RawValue != null)
{ {
return ModelBindingHelper.ConvertTo(modelState.RawValue, destinationType, culture: null); return ModelBindingHelper.ConvertTo(entry.RawValue, destinationType, culture: null);
} }
return null; return null;
@ -1228,8 +1228,8 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
} }
// If there are any errors for a named field, we add the CSS attribute. // If there are any errors for a named field, we add the CSS attribute.
ModelState modelState; ModelStateEntry entry;
if (viewContext.ViewData.ModelState.TryGetValue(fullName, out modelState) && modelState.Errors.Count > 0) if (viewContext.ViewData.ModelState.TryGetValue(fullName, out entry) && entry.Errors.Count > 0)
{ {
tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName); tagBuilder.AddCssClass(HtmlHelper.ValidationInputCssClassName);
} }

View File

@ -95,7 +95,7 @@ namespace System.Web.Http
Message = ShimResources.HttpError_BadRequest; Message = ShimResources.HttpError_BadRequest;
var modelStateError = new HttpError(); var modelStateError = new HttpError();
foreach (KeyValuePair<string, ModelState> keyModelStatePair in modelState) foreach (KeyValuePair<string, ModelStateEntry> keyModelStatePair in modelState)
{ {
var key = keyModelStatePair.Key; var key = keyModelStatePair.Key;
var errors = keyModelStatePair.Value.Errors; var errors = keyModelStatePair.Value.Errors;

View File

@ -15,14 +15,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid(ModelValidationState validationState) public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid(ModelValidationState validationState)
{ {
// Arrange // Arrange
var modelState = new ModelState var entry = new ModelStateEntry
{ {
ValidationState = validationState ValidationState = validationState
}; };
var source = new ModelStateDictionary var source = new ModelStateDictionary
{ {
{ "key", modelState } { "key", entry }
}; };
// Act // Act
@ -36,14 +36,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void MarkFieldSkipped_MarksFieldAsSkipped_IfKeyIsNotPresent() public void MarkFieldSkipped_MarksFieldAsSkipped_IfKeyIsNotPresent()
{ {
// Arrange // Arrange
var modelState = new ModelState var entry = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Valid ValidationState = ModelValidationState.Valid
}; };
var source = new ModelStateDictionary var source = new ModelStateDictionary();
{
};
// Act // Act
source.MarkFieldSkipped("key"); source.MarkFieldSkipped("key");
@ -58,14 +56,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void MarkFieldSkipped_Throws_IfStateIsInvalid() public void MarkFieldSkipped_Throws_IfStateIsInvalid()
{ {
// Arrange // Arrange
var modelState = new ModelState var entry = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Invalid ValidationState = ModelValidationState.Invalid
}; };
var source = new ModelStateDictionary var source = new ModelStateDictionary
{ {
{ "key", modelState } { "key", entry }
}; };
// Act // Act
@ -83,14 +81,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void MarkFieldValid_MarksFieldAsValid_IfStateIsNotInvalid(ModelValidationState validationState) public void MarkFieldValid_MarksFieldAsValid_IfStateIsNotInvalid(ModelValidationState validationState)
{ {
// Arrange // Arrange
var modelState = new ModelState var entry = new ModelStateEntry
{ {
ValidationState = validationState ValidationState = validationState
}; };
var source = new ModelStateDictionary var source = new ModelStateDictionary
{ {
{ "key", modelState } { "key", entry }
}; };
// Act // Act
@ -119,14 +117,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void MarkFieldValid_Throws_IfStateIsInvalid() public void MarkFieldValid_Throws_IfStateIsInvalid()
{ {
// Arrange // Arrange
var modelState = new ModelState var entry = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Invalid ValidationState = ModelValidationState.Invalid
}; };
var source = new ModelStateDictionary var source = new ModelStateDictionary
{ {
{ "key", modelState } { "key", entry }
}; };
// Act // Act
@ -142,10 +140,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void CopyConstructor_CopiesModelStateData() public void CopyConstructor_CopiesModelStateData()
{ {
// Arrange // Arrange
var modelState = new ModelState(); var entry = new ModelStateEntry();
var source = new ModelStateDictionary var source = new ModelStateDictionary
{ {
{ "key", modelState } { "key", entry }
}; };
// Act // Act
@ -154,8 +152,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Assert // Assert
Assert.Equal(0, target.ErrorCount); Assert.Equal(0, target.ErrorCount);
Assert.Equal(1, target.Count); Assert.Equal(1, target.Count);
Assert.Same(modelState, target["key"]); Assert.Same(entry, target["key"]);
Assert.IsType<Dictionary<string, ModelState>>(target.InnerDictionary); Assert.IsType<Dictionary<string, ModelStateEntry>>(target.InnerDictionary);
} }
[Fact] [Fact]
@ -202,7 +200,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var oldDictionary = new ModelStateDictionary() var oldDictionary = new ModelStateDictionary()
{ {
{ "foo", new ModelState() { RawValue = "bar" } } { "foo", new ModelStateEntry() { RawValue = "bar" } }
}; };
// Act // Act
@ -217,10 +215,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetFieldValidationState_ReturnsUnvalidatedIfDictionaryDoesNotContainKey() public void GetFieldValidationState_ReturnsUnvalidatedIfDictionaryDoesNotContainKey()
{ {
// Arrange // Arrange
var msd = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
// Act // Act
var validationState = msd.GetFieldValidationState("foo"); var validationState = dictionary.GetFieldValidationState("foo");
// Assert // Assert
Assert.Equal(ModelValidationState.Unvalidated, validationState); Assert.Equal(ModelValidationState.Unvalidated, validationState);
@ -230,11 +228,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetValidationState_ReturnsValidationStateForKey_IgnoresChildren() public void GetValidationState_ReturnsValidationStateForKey_IgnoresChildren()
{ {
// Arrange // Arrange
var msd = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
msd.AddModelError("foo.bar", "error text"); dictionary.AddModelError("foo.bar", "error text");
// Act // Act
var validationState = msd.GetValidationState("foo"); var validationState = dictionary.GetValidationState("foo");
// Assert // Assert
Assert.Equal(ModelValidationState.Unvalidated, validationState); Assert.Equal(ModelValidationState.Unvalidated, validationState);
@ -248,11 +246,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetFieldValidationState_ReturnsInvalidIfKeyChildContainsErrors(string key) public void GetFieldValidationState_ReturnsInvalidIfKeyChildContainsErrors(string key)
{ {
// Arrange // Arrange
var msd = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
msd.AddModelError(key, "error text"); dictionary.AddModelError(key, "error text");
// Act // Act
var validationState = msd.GetFieldValidationState("foo"); var validationState = dictionary.GetFieldValidationState("foo");
// Assert // Assert
Assert.Equal(ModelValidationState.Invalid, validationState); Assert.Equal(ModelValidationState.Invalid, validationState);
@ -266,17 +264,17 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetFieldValidationState_ReturnsValidIfModelStateDoesNotContainErrors(string key) public void GetFieldValidationState_ReturnsValidIfModelStateDoesNotContainErrors(string key)
{ {
// Arrange // Arrange
var validState = new ModelState var validState = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Valid ValidationState = ModelValidationState.Valid
}; };
var msd = new ModelStateDictionary var dictionary = new ModelStateDictionary
{ {
{ key, validState } { key, validState }
}; };
// Act // Act
var validationState = msd.GetFieldValidationState("foo"); var validationState = dictionary.GetFieldValidationState("foo");
// Assert // Assert
Assert.Equal(ModelValidationState.Valid, validationState); Assert.Equal(ModelValidationState.Valid, validationState);
@ -288,11 +286,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetFieldValidationState_IndexedPrefix_ReturnsInvalidIfKeyChildContainsErrors(string key) public void GetFieldValidationState_IndexedPrefix_ReturnsInvalidIfKeyChildContainsErrors(string key)
{ {
// Arrange // Arrange
var msd = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
msd.AddModelError(key, "error text"); dictionary.AddModelError(key, "error text");
// Act // Act
var validationState = msd.GetFieldValidationState("[0].foo"); var validationState = dictionary.GetFieldValidationState("[0].foo");
// Assert // Assert
Assert.Equal(ModelValidationState.Invalid, validationState); Assert.Equal(ModelValidationState.Invalid, validationState);
@ -304,17 +302,17 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetFieldValidationState_IndexedPrefix_ReturnsValidIfModelStateDoesNotContainErrors(string key) public void GetFieldValidationState_IndexedPrefix_ReturnsValidIfModelStateDoesNotContainErrors(string key)
{ {
// Arrange // Arrange
var validState = new ModelState var validState = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Valid ValidationState = ModelValidationState.Valid
}; };
var msd = new ModelStateDictionary var dictionary = new ModelStateDictionary
{ {
{ key, validState } { key, validState }
}; };
// Act // Act
var validationState = msd.GetFieldValidationState("[0].foo"); var validationState = dictionary.GetFieldValidationState("[0].foo");
// Assert // Assert
Assert.Equal(ModelValidationState.Valid, validationState); Assert.Equal(ModelValidationState.Valid, validationState);
@ -324,11 +322,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void IsValidPropertyReturnsFalseIfErrors() public void IsValidPropertyReturnsFalseIfErrors()
{ {
// Arrange // Arrange
var errorState = new ModelState var errorState = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Invalid ValidationState = ModelValidationState.Invalid
}; };
var validState = new ModelState var validState = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Valid ValidationState = ModelValidationState.Valid
}; };
@ -354,15 +352,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var dictionary = new ModelStateDictionary() var dictionary = new ModelStateDictionary()
{ {
{ "foo", new ModelState { "foo", new ModelStateEntry
{ {
ValidationState = ModelValidationState.Valid, ValidationState = ModelValidationState.Valid,
} }
}, },
{ "baz", new ModelState { "baz", new ModelStateEntry
{ {
ValidationState = ModelValidationState.Skipped, ValidationState = ModelValidationState.Skipped,
} }
} }
}; };
@ -379,11 +377,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void IsValidPropertyReturnsFalse_IfSomeFieldsAreNotValidated() public void IsValidPropertyReturnsFalse_IfSomeFieldsAreNotValidated()
{ {
// Arrange // Arrange
var errorState = new ModelState var errorState = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Invalid ValidationState = ModelValidationState.Invalid
}; };
var validState = new ModelState var validState = new ModelStateEntry
{ {
ValidationState = ModelValidationState.Valid ValidationState = ModelValidationState.Valid
}; };
@ -392,7 +390,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
{ "foo", validState }, { "foo", validState },
{ "baz", errorState }, { "baz", errorState },
{ "qux", new ModelState() } { "qux", new ModelStateEntry() }
}; };
// Act // Act
@ -408,29 +406,29 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void MergeCopiesDictionaryEntries() public void MergeCopiesDictionaryEntries()
{ {
// Arrange // Arrange
var fooDict = new ModelStateDictionary() { { "foo", new ModelState() } }; var dictionary1 = new ModelStateDictionary { { "foo", new ModelStateEntry() } };
var barDict = new ModelStateDictionary() { { "bar", new ModelState() } }; var dictionary2 = new ModelStateDictionary { { "bar", new ModelStateEntry() } };
// Act // Act
fooDict.Merge(barDict); dictionary1.Merge(dictionary2);
// Assert // Assert
Assert.Equal(2, fooDict.Count); Assert.Equal(2, dictionary1.Count);
Assert.Equal(barDict["bar"], fooDict["bar"]); Assert.Equal(dictionary2["bar"], dictionary1["bar"]);
} }
[Fact] [Fact]
public void MergeDoesNothingIfParameterIsNull() public void MergeDoesNothingIfParameterIsNull()
{ {
// Arrange // Arrange
var fooDict = new ModelStateDictionary() { { "foo", new ModelState() } }; var dictionary = new ModelStateDictionary() { { "foo", new ModelStateEntry() } };
// Act // Act
fooDict.Merge(null); dictionary.Merge(null);
// Assert // Assert
Assert.Single(fooDict); Assert.Single(dictionary);
Assert.True(fooDict.ContainsKey("foo")); Assert.True(dictionary.ContainsKey("foo"));
} }
[Fact] [Fact]
@ -491,7 +489,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["user.Address"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["user.Address"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary.SetModelValue("user.Name", new string[] { "some value" }, "some value"); dictionary.SetModelValue("user.Name", new string[] { "some value" }, "some value");
dictionary.AddModelError("user.Age", "Age is not a valid int"); dictionary.AddModelError("user.Age", "Age is not a valid int");
@ -510,11 +508,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["user.Address"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["user.Address"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["user.Name"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["user.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary.AddModelError("user.Age", "Age is not a valid int"); dictionary.AddModelError("user.Age", "Age is not a valid int");
dictionary["[0].product.Name"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["[0].product.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["[0].product.Age[0]"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["[0].product.Age[0]"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary.AddModelError("[1].product.Name", "Name is invalid"); dictionary.AddModelError("[1].product.Name", "Name is invalid");
// Act // Act
@ -529,8 +527,8 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["user.Address"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["user.Address"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["user.Name"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["user.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
// Act // Act
var validationState = dictionary.GetFieldValidationState("user"); var validationState = dictionary.GetFieldValidationState("user");
@ -761,15 +759,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["Property1"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["Property1"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["Property2"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Property2"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Property2", "Property2 invalid."); dictionary.AddModelError("Property2", "Property2 invalid.");
dictionary["Property3"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Property3"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Property3", "Property invalid."); dictionary.AddModelError("Property3", "Property invalid.");
dictionary["Property4"] = new ModelState { ValidationState = ModelValidationState.Skipped }; dictionary["Property4"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
// Act // Act
dictionary.ClearValidationState("Property1"); dictionary.ClearValidationState("Property1");
@ -793,22 +791,22 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["Product"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["Product"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["Product.Detail1"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Product.Detail1"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid."); dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid.");
dictionary["Product.Detail2[0]"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Product.Detail2[0]"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail2[0]", "Product Detail2[0] invalid."); dictionary.AddModelError("Product.Detail2[0]", "Product Detail2[0] invalid.");
dictionary["Product.Detail2[1]"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Product.Detail2[1]"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail2[1]", "Product Detail2[1] invalid."); dictionary.AddModelError("Product.Detail2[1]", "Product Detail2[1] invalid.");
dictionary["Product.Detail2[2]"] = new ModelState { ValidationState = ModelValidationState.Skipped }; dictionary["Product.Detail2[2]"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
dictionary["Product.Detail3"] = new ModelState { ValidationState = ModelValidationState.Skipped }; dictionary["Product.Detail3"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
dictionary["ProductName"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["ProductName"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("ProductName", "ProductName invalid."); dictionary.AddModelError("ProductName", "ProductName invalid.");
// Act // Act
@ -837,15 +835,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["Product"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["Product"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["Product.Detail1"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Product.Detail1"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid."); dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid.");
dictionary["Product.Detail1.Name"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Product.Detail1.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Product.Detail1.Name", "Product Detail1 Name invalid."); dictionary.AddModelError("Product.Detail1.Name", "Product Detail1 Name invalid.");
dictionary["Product.Detail1Name"] = new ModelState { ValidationState = ModelValidationState.Skipped }; dictionary["Product.Detail1Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
// Act // Act
dictionary.ClearValidationState("Product.Detail1"); dictionary.ClearValidationState("Product.Detail1");
@ -867,15 +865,15 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["Property1"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["Property1"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["Property2"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Property2"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Property2", "Property2 invalid."); dictionary.AddModelError("Property2", "Property2 invalid.");
dictionary["Property3"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Property3"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Property3", "Property invalid."); dictionary.AddModelError("Property3", "Property invalid.");
dictionary["Property4"] = new ModelState { ValidationState = ModelValidationState.Skipped }; dictionary["Property4"] = new ModelStateEntry { ValidationState = ModelValidationState.Skipped };
// Act // Act
dictionary.ClearValidationState(modelKey); dictionary.ClearValidationState(modelKey);

View File

@ -715,12 +715,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var metadataProvider = new EmptyModelMetadataProvider(); var metadataProvider = new EmptyModelMetadataProvider();
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["Name"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Name", "MyProperty invalid."); dictionary.AddModelError("Name", "MyProperty invalid.");
dictionary["Id"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["Id"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("Id", "Id invalid."); dictionary.AddModelError("Id", "Id invalid.");
dictionary.AddModelError("Id", "Id is required."); dictionary.AddModelError("Id", "Id is required.");
dictionary["Category"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["Category"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
// Act // Act
ModelBindingHelper.ClearValidationStateForModel( ModelBindingHelper.ClearValidationStateForModel(
@ -746,16 +746,16 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var metadataProvider = new EmptyModelMetadataProvider(); var metadataProvider = new EmptyModelMetadataProvider();
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["[0].Name"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["[0].Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("[0].Name", "Name invalid."); dictionary.AddModelError("[0].Name", "Name invalid.");
dictionary["[0].Id"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["[0].Id"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("[0].Id", "Id invalid."); dictionary.AddModelError("[0].Id", "Id invalid.");
dictionary.AddModelError("[0].Id", "Id required."); dictionary.AddModelError("[0].Id", "Id required.");
dictionary["[0].Category"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["[0].Category"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["[1].Name"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["[1].Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["[1].Id"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["[1].Id"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["[1].Category"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["[1].Category"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("[1].Category", "Category invalid."); dictionary.AddModelError("[1].Category", "Category invalid.");
// Act // Act
@ -793,20 +793,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
var metadataProvider = new TestModelMetadataProvider(); var metadataProvider = new TestModelMetadataProvider();
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary["product.Name"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["product.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("product.Name", "Name invalid."); dictionary.AddModelError("product.Name", "Name invalid.");
dictionary["product.Id"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["product.Id"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("product.Id", "Id invalid."); dictionary.AddModelError("product.Id", "Id invalid.");
dictionary.AddModelError("product.Id", "Id required."); dictionary.AddModelError("product.Id", "Id required.");
dictionary["product.Category"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["product.Category"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["product.Category.Name"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["product.Category.Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["product.Order[0].Name"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["product.Order[0].Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("product.Order[0].Name", "Order name invalid."); dictionary.AddModelError("product.Order[0].Name", "Order name invalid.");
dictionary["product.Order[0].Address.Street"] = dictionary["product.Order[0].Address.Street"] =
new ModelState { ValidationState = ModelValidationState.Invalid }; new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("product.Order[0].Address.Street", "Street invalid."); dictionary.AddModelError("product.Order[0].Address.Street", "Street invalid.");
dictionary["product.Order[1].Name"] = new ModelState { ValidationState = ModelValidationState.Valid }; dictionary["product.Order[1].Name"] = new ModelStateEntry { ValidationState = ModelValidationState.Valid };
dictionary["product.Order[0]"] = new ModelState { ValidationState = ModelValidationState.Invalid }; dictionary["product.Order[0]"] = new ModelStateEntry { ValidationState = ModelValidationState.Invalid };
dictionary.AddModelError("product.Order[0]", "Order invalid."); dictionary.AddModelError("product.Order[0]", "Order invalid.");
// Act // Act

View File

@ -809,9 +809,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
Assert.Single(modelStateDictionary); Assert.Single(modelStateDictionary);
// Check Age error. // Check Age error.
ModelState modelState; ModelStateEntry entry;
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out modelState)); Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out entry));
var modelError = Assert.Single(modelState.Errors); var modelError = Assert.Single(entry.Errors);
Assert.Null(modelError.Exception); Assert.Null(modelError.Exception);
Assert.NotNull(modelError.ErrorMessage); Assert.NotNull(modelError.ErrorMessage);
Assert.Equal("A value for the 'Age' property was not provided.", modelError.ErrorMessage); Assert.Equal("A value for the 'Age' property was not provided.", modelError.ErrorMessage);
@ -859,9 +859,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
Assert.Single(modelStateDictionary); Assert.Single(modelStateDictionary);
// Check Age error. // Check Age error.
ModelState modelState; ModelStateEntry entry;
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out modelState)); Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out entry));
var modelError = Assert.Single(modelState.Errors); var modelError = Assert.Single(entry.Errors);
Assert.Null(modelError.Exception); Assert.Null(modelError.Exception);
Assert.NotNull(modelError.ErrorMessage); Assert.NotNull(modelError.ErrorMessage);
Assert.Equal("A value for the 'Age' property was not provided.", modelError.ErrorMessage); Assert.Equal("A value for the 'Age' property was not provided.", modelError.ErrorMessage);
@ -914,11 +914,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
Assert.Equal(1, modelStateDictionary.Count); Assert.Equal(1, modelStateDictionary.Count);
// Check Age error. // Check Age error.
ModelState modelState; ModelStateEntry entry;
Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out modelState)); Assert.True(modelStateDictionary.TryGetValue("theModel.Age", out entry));
Assert.Equal(ModelValidationState.Invalid, modelState.ValidationState); Assert.Equal(ModelValidationState.Invalid, entry.ValidationState);
var modelError = Assert.Single(modelState.Errors); var modelError = Assert.Single(entry.Errors);
Assert.Equal(string.Empty, modelError.ErrorMessage); Assert.Equal(string.Empty, modelError.ErrorMessage);
Assert.IsType<NullReferenceException>(modelError.Exception); Assert.IsType<NullReferenceException>(modelError.Exception);
} }

View File

@ -651,9 +651,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
var validator = CreateValidator(new SimpleTypesExcludeFilter()); var validator = CreateValidator(new SimpleTypesExcludeFilter());
modelState.Add("items[0]", new ModelState()); modelState.Add("items[0]", new ModelStateEntry());
modelState.Add("items[1]", new ModelState()); modelState.Add("items[1]", new ModelStateEntry());
modelState.Add("items[2]", new ModelState()); modelState.Add("items[2]", new ModelStateEntry());
validationState.Add(model, new ValidationStateEntry() validationState.Add(model, new ValidationStateEntry()
{ {
Key = "items", Key = "items",
@ -698,10 +698,10 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Validation
{ "BarKey", "BarValue" } { "BarKey", "BarValue" }
}; };
modelState.Add("items[0].Key", new ModelState()); modelState.Add("items[0].Key", new ModelStateEntry());
modelState.Add("items[0].Value", new ModelState()); modelState.Add("items[0].Value", new ModelStateEntry());
modelState.Add("items[1].Key", new ModelState()); modelState.Add("items[1].Key", new ModelStateEntry());
modelState.Add("items[1].Value", new ModelState()); modelState.Add("items[1].Value", new ModelStateEntry());
validationState.Add(model, new ValidationStateEntry() { Key = "items" }); validationState.Add(model, new ValidationStateEntry() { Key = "items" });
// Act // Act

View File

@ -72,10 +72,10 @@ namespace Microsoft.AspNet.Mvc
var modelState = new ModelStateDictionary(); var modelState = new ModelStateDictionary();
modelState.Add( modelState.Add(
"key1", "key1",
new ModelState()); new ModelStateEntry());
modelState.Add( modelState.Add(
"key2", "key2",
new ModelState()); new ModelStateEntry());
// Act // Act
var serializableError = new SerializableError(modelState); var serializableError = new SerializableError(modelState);

View File

@ -155,7 +155,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("Text", new ModelState()); dictionary.Add("Text", new ModelStateEntry());
// Act // Act
dictionary.Remove<TestModel>(model => model.Text); dictionary.Remove<TestModel>(model => model.Text);
@ -169,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("Child.Text", new ModelState()); dictionary.Add("Child.Text", new ModelStateEntry());
// Act // Act
dictionary.Remove<TestModel>(model => model.Child.Text); dictionary.Remove<TestModel>(model => model.Child.Text);
@ -183,7 +183,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
// Arrange // Arrange
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("Child.Value", new ModelState()); dictionary.Add("Child.Value", new ModelStateEntry());
// Act // Act
dictionary.Remove<TestModel>(model => model.Child.Value); dictionary.Remove<TestModel>(model => model.Child.Value);
@ -198,7 +198,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
// Arrange // Arrange
var variable = "Test"; var variable = "Test";
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("variable", new ModelState()); dictionary.Add("variable", new ModelStateEntry());
// Act // Act
dictionary.Remove<TestModel>(model => variable); dictionary.Remove<TestModel>(model => variable);
@ -211,12 +211,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void RemoveAll_ForSingleExpression_RemovesModelStateKeys() public void RemoveAll_ForSingleExpression_RemovesModelStateKeys()
{ {
// Arrange // Arrange
var state = new ModelState(); var state = new ModelStateEntry();
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("Key", state); dictionary.Add("Key", state);
dictionary.Add("Text", new ModelState()); dictionary.Add("Text", new ModelStateEntry());
dictionary.Add("Text.Length", new ModelState()); dictionary.Add("Text.Length", new ModelStateEntry());
// Act // Act
dictionary.RemoveAll<TestModel>(model => model.Text); dictionary.RemoveAll<TestModel>(model => model.Text);
@ -232,12 +232,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void RemoveAll_ForRelationExpression_RemovesModelStateKeys() public void RemoveAll_ForRelationExpression_RemovesModelStateKeys()
{ {
// Arrange // Arrange
var state = new ModelState(); var state = new ModelStateEntry();
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("Key", state); dictionary.Add("Key", state);
dictionary.Add("Child", new ModelState()); dictionary.Add("Child", new ModelStateEntry());
dictionary.Add("Child.Text", new ModelState()); dictionary.Add("Child.Text", new ModelStateEntry());
// Act // Act
dictionary.RemoveAll<TestModel>(model => model.Child); dictionary.RemoveAll<TestModel>(model => model.Child);
@ -253,11 +253,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void RemoveAll_ForImplicitlyCastedToObjectExpression_RemovesModelStateKeys() public void RemoveAll_ForImplicitlyCastedToObjectExpression_RemovesModelStateKeys()
{ {
// Arrange // Arrange
var state = new ModelState(); var state = new ModelStateEntry();
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("Child", state); dictionary.Add("Child", state);
dictionary.Add("Child.Value", new ModelState()); dictionary.Add("Child.Value", new ModelStateEntry());
// Act // Act
dictionary.RemoveAll<TestModel>(model => model.Child.Value); dictionary.RemoveAll<TestModel>(model => model.Child.Value);
@ -274,13 +274,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
// Arrange // Arrange
var variable = "Test"; var variable = "Test";
var state = new ModelState(); var state = new ModelStateEntry();
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("Key", state); dictionary.Add("Key", state);
dictionary.Add("variable", new ModelState()); dictionary.Add("variable", new ModelStateEntry());
dictionary.Add("variable.Text", new ModelState()); dictionary.Add("variable.Text", new ModelStateEntry());
dictionary.Add("variable.Value", new ModelState()); dictionary.Add("variable.Value", new ModelStateEntry());
// Act // Act
dictionary.RemoveAll<TestModel>(model => variable); dictionary.RemoveAll<TestModel>(model => variable);
@ -296,14 +296,14 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void RemoveAll_ForModelExpression_RemovesModelPropertyKeys() public void RemoveAll_ForModelExpression_RemovesModelPropertyKeys()
{ {
// Arrange // Arrange
var state = new ModelState(); var state = new ModelStateEntry();
var dictionary = new ModelStateDictionary(); var dictionary = new ModelStateDictionary();
dictionary.Add("Key", state); dictionary.Add("Key", state);
dictionary.Add("Text", new ModelState()); dictionary.Add("Text", new ModelStateEntry());
dictionary.Add("Child", new ModelState()); dictionary.Add("Child", new ModelStateEntry());
dictionary.Add("Child.Text", new ModelState()); dictionary.Add("Child.Text", new ModelStateEntry());
dictionary.Add("Child.NoValue", new ModelState()); dictionary.Add("Child.NoValue", new ModelStateEntry());
// Act // Act
dictionary.RemoveAll<TestModel>(model => model); dictionary.RemoveAll<TestModel>(model => model);

View File

@ -260,7 +260,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
viewData["FieldPrefix.Name"] = "View data dictionary value"; viewData["FieldPrefix.Name"] = "View data dictionary value";
viewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix"; viewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix";
var modelState = new ModelState(); var modelState = new ModelStateEntry();
modelState.RawValue = new string[] { "Attempted name value" }; modelState.RawValue = new string[] { "Attempted name value" };
modelState.AttemptedValue = "Attempted name value"; modelState.AttemptedValue = "Attempted name value";
viewData.ModelState["FieldPrefix.Name"] = modelState; viewData.ModelState["FieldPrefix.Name"] = modelState;
@ -285,7 +285,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
viewData["Name"] = "View data dictionary value"; viewData["Name"] = "View data dictionary value";
viewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix"; viewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix";
var modelState = new ModelState(); var modelState = new ModelStateEntry();
modelState.RawValue = new string[] { "Attempted name value" }; modelState.RawValue = new string[] { "Attempted name value" };
modelState.AttemptedValue = "Attempted name value"; modelState.AttemptedValue = "Attempted name value";
viewData.ModelState["FieldPrefix.Name"] = modelState; viewData.ModelState["FieldPrefix.Name"] = modelState;

View File

@ -362,9 +362,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
idAttributeDotReplacement: "$"); idAttributeDotReplacement: "$");
helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix";
helper.ViewData.ModelState.Clear(); helper.ViewData.ModelState.Clear();
helper.ViewData.ModelState.Add("Property1", GetModelState("modelstate-without-prefix")); helper.ViewData.ModelState.Add("Property1", GetModelStateEntry("modelstate-without-prefix"));
helper.ViewData.ModelState.Add("MyPrefix.Property1", GetModelState("modelstate-with-prefix")); helper.ViewData.ModelState.Add("MyPrefix.Property1", GetModelStateEntry("modelstate-with-prefix"));
helper.ViewData.ModelState.Add("MyPrefix$Property1", GetModelState("modelstate-with-iddotreplacement")); helper.ViewData.ModelState.Add("MyPrefix$Property1", GetModelStateEntry("modelstate-with-iddotreplacement"));
// Act // Act
var result = helper.Hidden("Property1", "explicit-value", htmlAttributes: null); var result = helper.Hidden("Property1", "explicit-value", htmlAttributes: null);
@ -661,9 +661,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
helper.ViewData.Model.Property1 = "propValue"; helper.ViewData.Model.Property1 = "propValue";
helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix"; helper.ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix = "MyPrefix";
helper.ViewData.ModelState.Clear(); helper.ViewData.ModelState.Clear();
helper.ViewData.ModelState.Add("Property1", GetModelState("modelstate-without-prefix")); helper.ViewData.ModelState.Add("Property1", GetModelStateEntry("modelstate-without-prefix"));
helper.ViewData.ModelState.Add("MyPrefix.Property1", GetModelState("modelstate-with-prefix")); helper.ViewData.ModelState.Add("MyPrefix.Property1", GetModelStateEntry("modelstate-with-prefix"));
helper.ViewData.ModelState.Add("MyPrefix$Property1", GetModelState("modelstate-with-iddotreplacement")); helper.ViewData.ModelState.Add("MyPrefix$Property1", GetModelStateEntry("modelstate-with-iddotreplacement"));
// Act // Act
var result = helper.HiddenFor(m => m.Property1, htmlAttributes: null); var result = helper.HiddenFor(m => m.Property1, htmlAttributes: null);
@ -803,9 +803,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
// Arrange // Arrange
var viewData = GetViewDataWithNullModelAndNonNullViewData(); var viewData = GetViewDataWithNullModelAndNonNullViewData();
viewData.ModelState.Add("pre.Property3[key]", GetModelState("Prop3Val")); viewData.ModelState.Add("pre.Property3[key]", GetModelStateEntry("Prop3Val"));
viewData.ModelState.Add("pre.Property4.Property5", GetModelState("Prop5Val")); viewData.ModelState.Add("pre.Property4.Property5", GetModelStateEntry("Prop5Val"));
viewData.ModelState.Add("pre.Property4.Property6[0]", GetModelState("Prop6Val")); viewData.ModelState.Add("pre.Property4.Property6[0]", GetModelStateEntry("Prop6Val"));
var helper = DefaultTemplatesUtilities.GetHtmlHelper(viewData); var helper = DefaultTemplatesUtilities.GetHtmlHelper(viewData);
viewData.TemplateInfo.HtmlFieldPrefix = "pre"; viewData.TemplateInfo.HtmlFieldPrefix = "pre";
@ -858,7 +858,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
var viewData = GetViewDataWithNonNullModel(); var viewData = GetViewDataWithNonNullModel();
viewData["Property1"] = "view-data-val"; viewData["Property1"] = "view-data-val";
viewData.ModelState.Add("Property1", GetModelState("ModelStateValue")); viewData.ModelState.Add("Property1", GetModelStateEntry("ModelStateValue"));
return viewData; return viewData;
} }
@ -871,9 +871,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
return viewData; return viewData;
} }
private static ModelState GetModelState(string value) private static ModelStateEntry GetModelStateEntry(string value)
{ {
return new ModelState return new ModelStateEntry
{ {
RawValue = new string[] { value }, RawValue = new string[] { value },
AttemptedValue = value, AttemptedValue = value,

View File

@ -325,9 +325,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
// Arrange // Arrange
var viewData = GetViewDataWithModelStateAndModelAndViewDataValues(); var viewData = GetViewDataWithModelStateAndModelAndViewDataValues();
viewData.ModelState.Add("pre.Property3[key]", GetModelState("Property3Val")); viewData.ModelState.Add("pre.Property3[key]", GetModelStateEntry("Property3Val"));
viewData.ModelState.Add("pre.Property4.Property5", GetModelState("Property5Val")); viewData.ModelState.Add("pre.Property4.Property5", GetModelStateEntry("Property5Val"));
viewData.ModelState.Add("pre.Property4.Property6[0]", GetModelState("Property6Val")); viewData.ModelState.Add("pre.Property4.Property6[0]", GetModelStateEntry("Property6Val"));
viewData["pre.Property3[key]"] = "vdd-value1"; viewData["pre.Property3[key]"] = "vdd-value1";
viewData["pre.Property4.Property5"] = "vdd-value2"; viewData["pre.Property4.Property5"] = "vdd-value2";
viewData["pre.Property4.Property6[0]"] = "vdd-value3"; viewData["pre.Property4.Property6[0]"] = "vdd-value3";
@ -358,7 +358,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
{ {
var viewData = GetViewDataWithNullModelAndNonEmptyViewData(); var viewData = GetViewDataWithNullModelAndNonEmptyViewData();
viewData.Model = new PasswordModel(); viewData.Model = new PasswordModel();
viewData.ModelState.Add("Property1", GetModelState("ModelStateValue")); viewData.ModelState.Add("Property1", GetModelStateEntry("ModelStateValue"));
return viewData; return viewData;
} }
@ -371,9 +371,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
return viewData; return viewData;
} }
private static ModelState GetModelState(string value) private static ModelStateEntry GetModelStateEntry(string value)
{ {
return new ModelState return new ModelStateEntry
{ {
RawValue = new string[] { value }, RawValue = new string[] { value },
AttemptedValue = value, AttemptedValue = value,

View File

@ -414,12 +414,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
var modelState = new ModelStateDictionary var modelState = new ModelStateDictionary
{ {
["Property1"] = new ModelState ["Property1"] = new ModelStateEntry
{ {
RawValue = new string[] { SelectSources.ModelStateEntry.ToString() }, RawValue = new string[] { SelectSources.ModelStateEntry.ToString() },
AttemptedValue = SelectSources.ModelStateEntry.ToString() AttemptedValue = SelectSources.ModelStateEntry.ToString()
}, },
["Prefix.Property1"] = new ModelState ["Prefix.Property1"] = new ModelStateEntry
{ {
RawValue = new string[] { SelectSources.ModelStateEntryWithPrefix.ToString() }, RawValue = new string[] { SelectSources.ModelStateEntryWithPrefix.ToString() },
AttemptedValue = SelectSources.ModelStateEntryWithPrefix.ToString() AttemptedValue = SelectSources.ModelStateEntryWithPrefix.ToString()
@ -455,12 +455,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
var modelState = new ModelStateDictionary var modelState = new ModelStateDictionary
{ {
["Property1"] = new ModelState ["Property1"] = new ModelStateEntry
{ {
RawValue = new string[] { SelectSources.ModelStateEntry.ToString() }, RawValue = new string[] { SelectSources.ModelStateEntry.ToString() },
AttemptedValue = SelectSources.ModelStateEntry.ToString() AttemptedValue = SelectSources.ModelStateEntry.ToString()
}, },
["Prefix.Property1"] = new ModelState ["Prefix.Property1"] = new ModelStateEntry
{ {
RawValue = new string[] { SelectSources.ModelStateEntryWithPrefix.ToString() }, RawValue = new string[] { SelectSources.ModelStateEntryWithPrefix.ToString() },
AttemptedValue = SelectSources.ModelStateEntryWithPrefix.ToString() AttemptedValue = SelectSources.ModelStateEntryWithPrefix.ToString()
@ -825,12 +825,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
var modelState = new ModelStateDictionary var modelState = new ModelStateDictionary
{ {
["Property1"] = new ModelState ["Property1"] = new ModelStateEntry
{ {
RawValue = new string[] { SelectSources.ModelStateEntry.ToString() }, RawValue = new string[] { SelectSources.ModelStateEntry.ToString() },
AttemptedValue = SelectSources.ModelStateEntry.ToString() AttemptedValue = SelectSources.ModelStateEntry.ToString()
}, },
["Prefix.Property1"] = new ModelState ["Prefix.Property1"] = new ModelStateEntry
{ {
RawValue = new string[] { SelectSources.ModelStateEntryWithPrefix.ToString() }, RawValue = new string[] { SelectSources.ModelStateEntryWithPrefix.ToString() },
AttemptedValue = SelectSources.ModelStateEntryWithPrefix.ToString() AttemptedValue = SelectSources.ModelStateEntryWithPrefix.ToString()
@ -866,12 +866,12 @@ namespace Microsoft.AspNet.Mvc.Rendering
var modelState = new ModelStateDictionary var modelState = new ModelStateDictionary
{ {
["Property1"] = new ModelState ["Property1"] = new ModelStateEntry
{ {
RawValue = new string[] { SelectSources.ModelStateEntry.ToString() }, RawValue = new string[] { SelectSources.ModelStateEntry.ToString() },
AttemptedValue = SelectSources.ModelStateEntry.ToString() AttemptedValue = SelectSources.ModelStateEntry.ToString()
}, },
["Prefix.Property1"] = new ModelState ["Prefix.Property1"] = new ModelStateEntry
{ {
RawValue = new string[] { SelectSources.ModelStateEntryWithPrefix.ToString() }, RawValue = new string[] { SelectSources.ModelStateEntryWithPrefix.ToString() },
AttemptedValue = SelectSources.ModelStateEntryWithPrefix.ToString() AttemptedValue = SelectSources.ModelStateEntryWithPrefix.ToString()

View File

@ -163,12 +163,12 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
viewData["StringProperty"] = "ViewDataValue"; viewData["StringProperty"] = "ViewDataValue";
viewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix"; viewData.TemplateInfo.HtmlFieldPrefix = "FieldPrefix";
var modelState = new ModelState(); var modelState = new ModelStateEntry();
modelState.AttemptedValue = "StringPropertyAttemptedValue"; modelState.AttemptedValue = "StringPropertyAttemptedValue";
modelState.RawValue = new string[] { "StringPropertyRawValue" }; modelState.RawValue = new string[] { "StringPropertyRawValue" };
viewData.ModelState["FieldPrefix.StringProperty"] = modelState; viewData.ModelState["FieldPrefix.StringProperty"] = modelState;
modelState = new ModelState(); modelState = new ModelStateEntry();
modelState.AttemptedValue = "ModelAttemptedValue"; modelState.AttemptedValue = "ModelAttemptedValue";
modelState.RawValue = new string[] { "ModelRawValue" }; modelState.RawValue = new string[] { "ModelRawValue" };
viewData.ModelState["FieldPrefix"] = modelState; viewData.ModelState["FieldPrefix"] = modelState;
@ -220,7 +220,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var viewData = helper.ViewData; var viewData = helper.ViewData;
viewData["StringProperty"] = "ViewDataValue <\"\">"; viewData["StringProperty"] = "ViewDataValue <\"\">";
var modelState = new ModelState(); var modelState = new ModelStateEntry();
modelState.AttemptedValue = "ObjectPropertyAttemptedValue <\"\">"; modelState.AttemptedValue = "ObjectPropertyAttemptedValue <\"\">";
modelState.RawValue = new string[] { "ObjectPropertyRawValue <\"\">" }; modelState.RawValue = new string[] { "ObjectPropertyRawValue <\"\">" };
viewData.ModelState["ObjectProperty"] = modelState; viewData.ModelState["ObjectProperty"] = modelState;

View File

@ -33,7 +33,12 @@ namespace System.Web.Http.Dispatcher
yield return new[] { new HttpError() }; yield return new[] { new HttpError() };
yield return new[] { new HttpError("error") }; yield return new[] { new HttpError("error") };
yield return new[] { new HttpError(new NotImplementedException(), true) }; yield return new[] { new HttpError(new NotImplementedException(), true) };
yield return new[] { new HttpError(new ModelStateDictionary() { { "key", new ModelState() { Errors = { new ModelError("error") } } } }, true) }; yield return new[] { new HttpError(
new ModelStateDictionary()
{
{ "key", new ModelStateEntry { Errors = { new ModelError("error") } } }
},
true) };
} }
} }