@@ -1365,10 +1365,39 @@ public void CanBindToFormWithFiles()
1365
1365
Assert . Equal ( $ "Profile Picture: { profilePicture . Name } ", Browser . Exists ( By . Id ( "profile-picture" ) ) . Text ) ;
1366
1366
Assert . Equal ( "Documents: 2" , Browser . Exists ( By . Id ( "documents" ) ) . Text ) ;
1367
1367
Assert . Equal ( "Images: 3" , Browser . Exists ( By . Id ( "images" ) ) . Text ) ;
1368
- Assert . Equal ( "Header Photo: Model.HeaderPhoto " , Browser . Exists ( By . Id ( "header-photo" ) ) . Text ) ;
1368
+ Assert . Equal ( $ "Header Photo: { headerPhoto . Name } ", Browser . Exists ( By . Id ( "header-photo" ) ) . Text ) ;
1369
1369
Assert . Equal ( "Total: 7" , Browser . Exists ( By . Id ( "form-collection" ) ) . Text ) ;
1370
1370
}
1371
1371
1372
+ [ Fact ]
1373
+ public void IBrowserFileNameReturnsFileNameNotFormFieldName ( )
1374
+ {
1375
+ // Create a file with a specific name to verify it's returned correctly
1376
+ var testFile = TempFile . Create ( _tempDirectory , "txt" , "Test file content for name validation." ) ;
1377
+
1378
+ var dispatchToForm = new DispatchToForm ( this )
1379
+ {
1380
+ Url = "forms/with-files" ,
1381
+ FormCssSelector = "form" ,
1382
+ FormIsEnhanced = false ,
1383
+ UpdateFormAction = ( ) =>
1384
+ {
1385
+ // Upload file to HeaderPhoto field (which is an IBrowserFile)
1386
+ // Form field name is "Model.HeaderPhoto" but file name should be testFile.Name
1387
+ Browser . Exists ( By . CssSelector ( "input[name='Model.HeaderPhoto']" ) ) . SendKeys ( testFile . Path ) ;
1388
+ }
1389
+ } ;
1390
+ DispatchToFormCore ( dispatchToForm ) ;
1391
+
1392
+ // Verify that IBrowserFile.Name returns the actual file name, not the form field name
1393
+ // Before the fix: would show "Header Photo: Model.HeaderPhoto" (form field name)
1394
+ // After the fix: should show "Header Photo: {testFile.Name}" (actual file name)
1395
+ Assert . Equal ( $ "Header Photo: { testFile . Name } ", Browser . Exists ( By . Id ( "header-photo" ) ) . Text ) ;
1396
+
1397
+ // Ensure the file name is actually different from the form field name to validate the test
1398
+ Assert . NotEqual ( "Model.HeaderPhoto" , testFile . Name ) ;
1399
+ }
1400
+
1372
1401
[ Theory ]
1373
1402
// [InlineData(true)] QuarantinedTest: https://github.com/dotnet/aspnetcore/issues/61882
1374
1403
[ InlineData ( false ) ]
0 commit comments