Skip to content

Commit b611dc1

Browse files
authored
Use default if no value was bound for parameter (#39427)
1 parent 67bdadf commit b611dc1

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/Mvc/Mvc.Core/src/Infrastructure/ControllerActionInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ private Task BindArgumentsAsync()
546546
{
547547
var parameterInfo = declaredParameterInfos[index];
548548

549-
if (!actionParameters.TryGetValue(parameterInfo.Name!, out var value))
549+
if (!actionParameters.TryGetValue(parameterInfo.Name!, out var value) || value is null)
550550
{
551551
value = actionMethodExecutor.GetDefaultValueForParameter(index);
552552
}

src/Mvc/test/Mvc.FunctionalTests/DefaultValuesTest.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,18 @@ public async Task Controller_WithDefaultParameterValues_ForStructs_ReturnsBoundV
9999
// Assert
100100
Assert.Equal(expected, response);
101101
}
102+
103+
[Fact]
104+
public async Task EchoValue_DefaultParameterValue_ForGlobbedPath()
105+
{
106+
// Arrange
107+
var expected = $"index.html";
108+
var url = "http://localhost/DefaultValues/EchoValue_DefaultParameterValue_ForGlobbedPath";
109+
110+
// Act
111+
var response = await Client.GetStringAsync(url);
112+
113+
// Assert
114+
Assert.Equal(expected, response);
115+
}
102116
}

src/Mvc/test/WebSites/BasicWebSite/Controllers/DefaultValuesController.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,11 @@ public string EchoValue_DefaultParameterValue_ForStructs(
2727
{
2828
return $"{guid}, {timeSpan}";
2929
}
30+
31+
[HttpGet]
32+
[Route("/[controller]/EchoValue_DefaultParameterValue_ForGlobbedPath/{**path}")]
33+
public string EchoValue_DefaultParameterValue_ForGlobbedPath(string path = "index.html")
34+
{
35+
return path;
36+
}
3037
}

0 commit comments

Comments
 (0)