diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/BindingMetadata.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/BindingMetadata.cs
index 6183b883a7..e7540642f2 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/BindingMetadata.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/BindingMetadata.cs
@@ -38,11 +38,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
///
/// Gets or sets a value indicating whether or not the request must contain a value for the model.
/// Will be ignored if the model metadata being created does not represent a property.
- /// See . If null, the value of
- /// will be computed based on
- /// .
+ /// See .
///
- public bool? IsBindingRequired { get; set; }
+ public bool IsBindingRequired { get; set; }
///
/// Gets or sets a value indicating whether or not the model is read-only. Will be ignored
diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs
index 4a83480299..28d3e1a695 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/Metadata/DefaultModelMetadata.cs
@@ -341,14 +341,9 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
{
_isBindingRequired = false;
}
- else if (BindingMetadata.IsBindingRequired.HasValue)
- {
- _isBindingRequired = BindingMetadata.IsBindingRequired;
- }
else
{
- // Default to IsBindingRequired = true for value types.
- _isBindingRequired = !AllowsNullValue(ModelType);
+ _isBindingRequired = BindingMetadata.IsBindingRequired;
}
}
diff --git a/src/Microsoft.AspNet.Mvc.Formatters.Xml/DataMemberRequiredBindingMetadataProvider.cs b/src/Microsoft.AspNet.Mvc.Formatters.Xml/DataMemberRequiredBindingMetadataProvider.cs
index e4eb241ffd..a9b6884c61 100644
--- a/src/Microsoft.AspNet.Mvc.Formatters.Xml/DataMemberRequiredBindingMetadataProvider.cs
+++ b/src/Microsoft.AspNet.Mvc.Formatters.Xml/DataMemberRequiredBindingMetadataProvider.cs
@@ -22,7 +22,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
return;
}
- if (context.BindingMetadata.IsBindingRequired == true)
+ if (context.BindingMetadata.IsBindingRequired)
{
// This value is already required, no need to look at attributes.
return;
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/DefaultModelMetadataTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/DefaultModelMetadataTest.cs
index f55875ebbc..5939d875fb 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/DefaultModelMetadataTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/DefaultModelMetadataTest.cs
@@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
Assert.False(metadata.HideSurroundingHtml);
Assert.True(metadata.HtmlEncode);
Assert.True(metadata.IsBindingAllowed);
- Assert.False(metadata.IsBindingRequired); // Defaults to false for reference types
+ Assert.False(metadata.IsBindingRequired);
Assert.False(metadata.IsComplexType);
Assert.False(metadata.IsCollectionType);
Assert.False(metadata.IsEnum);
@@ -223,49 +223,6 @@ namespace Microsoft.AspNet.Mvc.ModelBinding.Metadata
Assert.False(isBindingRequired);
}
- [Theory]
- [InlineData(typeof(string))]
- [InlineData(typeof(IDisposable))]
- [InlineData(typeof(Nullable))]
- public void IsBindingRequired_ReturnsFalse_ForNullablePropertyTypes(Type modelType)
- {
- // Arrange
- var provider = new EmptyModelMetadataProvider();
- var detailsProvider = new EmptyCompositeMetadataDetailsProvider();
-
- var key = ModelMetadataIdentity.ForProperty(modelType, "Test", typeof(string));
- var cache = new DefaultMetadataDetails(key, new ModelAttributes(new object[0]));
-
- var metadata = new DefaultModelMetadata(provider, detailsProvider, cache);
-
- // Act
- var isBindingRequired = metadata.IsBindingRequired;
-
- // Assert
- Assert.False(isBindingRequired);
- }
-
- [Theory]
- [InlineData(typeof(int))]
- [InlineData(typeof(DayOfWeek))]
- public void IsBindingRequired_ReturnsTrue_ForNonNullablePropertyTypes(Type modelType)
- {
- // Arrange
- var provider = new EmptyModelMetadataProvider();
- var detailsProvider = new EmptyCompositeMetadataDetailsProvider();
-
- var key = ModelMetadataIdentity.ForProperty(modelType, "Test", typeof(string));
- var cache = new DefaultMetadataDetails(key, new ModelAttributes(new object[0]));
-
- var metadata = new DefaultModelMetadata(provider, detailsProvider, cache);
-
- // Act
- var isBindingRequired = metadata.IsBindingRequired;
-
- // Assert
- Assert.True(isBindingRequired);
- }
-
[Theory]
[InlineData(typeof(string))]
[InlineData(typeof(IDisposable))]
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs
index 5fbc79b1f9..a7f82e0424 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/MutableObjectModelBinderTest.cs
@@ -1050,7 +1050,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
}
[Fact]
- public void ProcessDto_ValueTypeProperty_NoValue_Error()
+ public void ProcessDto_ValueTypeProperty_NoValue_NoError()
{
// Arrange
var model = new Person();
@@ -1083,14 +1083,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
testableBinder.ProcessDto(bindingContext, dto, modelValidationNode);
// Assert
- Assert.False(modelState.IsValid);
-
- var entry = modelState["theModel." + nameof(Person.ValueTypeRequiredWithDefaultValue)];
- var error = Assert.Single(entry.Errors);
- Assert.Equal(
- $"A value for the '{nameof(Person.ValueTypeRequiredWithDefaultValue)}' property was not provided.",
- error.ErrorMessage);
- Assert.Null(error.Exception);
+ Assert.True(modelState.IsValid);
}
[Fact]
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/HtmlGenerationTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/HtmlGenerationTest.cs
index 2536f0c926..a5d4990fee 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/HtmlGenerationTest.cs
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/HtmlGenerationTest.cs
@@ -196,12 +196,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Customer/HtmlGeneration_Customer");
var nameValueCollection = new List>
{
- new KeyValuePair("Number", "0"),
+ new KeyValuePair("Number", string.Empty),
new KeyValuePair("Name", string.Empty),
new KeyValuePair("Email", string.Empty),
new KeyValuePair("PhoneNumber", string.Empty),
- new KeyValuePair("Password", string.Empty),
- new KeyValuePair("Gender", "Female"),
+ new KeyValuePair("Password", string.Empty)
};
request.Content = new FormUrlEncodedContent(nameValueCollection);
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs
index f512f3240e..dd1496b377 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingFromQueryTest.cs
@@ -122,12 +122,8 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
// Assert
var body = await response.Content.ReadAsStringAsync();
var result = JsonConvert.DeserializeObject(body);
-
- Assert.Collection(
- result.ModelStateErrors,
- e => Assert.Equal("TestEmployees[0].EmployeeId", e),
- e => Assert.Equal("TestEmployees[0].EmployeeTaxId", e),
- e => Assert.Equal("TestEmployees[0].Age", e));
+ var error = Assert.Single(result.ModelStateErrors);
+ Assert.Equal("TestEmployees[0].EmployeeId", error);
}
}
}
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs
index af7257a2d5..696f366d9d 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ModelBindingTest.cs
@@ -2218,7 +2218,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
// Arrange
var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
var client = server.CreateClient();
- var url = "http://localhost/TryUpdateModel/TryUpdateModel_ClearsModelStateEntries?id=5&price=1";
+ var url = "http://localhost/TryUpdateModel/TryUpdateModel_ClearsModelStateEntries";
// Act
var response = await client.GetAsync(url);
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Customer.Index.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Customer.Index.html
index a32dfd7f63..7d6cf27c87 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Customer.Index.html
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Customer.Index.html
@@ -3,8 +3,8 @@