aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Strange behavior during MVC Model Binding

Open simonare opened this issue 7 years ago • 2 comments

Describe the bug

Wrong object is binded to controller action parameter when dynamic and object types are used.

To Reproduce

Steps to reproduce the behavior:

Using Asp.Net Core 2.2

[HttpPut("{pId}/Constraints")]
public async Task<IActionResult> PutConstraints([FromRoute]Guid pId, [FromBody] dynamic constraints)
 {
         ....            
}

Results with

    public async Task<IActionResult> PutConstraints([FromRoute]Guid pId, [FromBody] dynamic[] constraints)
    {
          ....
    }

image

Whereas returns correct object

image

Expected behavior

dynamic needs to give same result with dynamic[] also object needs to give same result with object[]

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

.NET Core SDK (reflecting any global.json): Version: 2.2.100 Commit: b9f2fa0ca8

.NET Core SDKs installed: 2.2.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]

Actual JSON Object

[  
   {  
      "id":"dd877c97-7dc5-4c07-b80e-310b04d98aa2",
      "type":"komisyon",
      "input":{  
         "pk":[  
            "00"
         ],
         "vadeMin":1,
         "vadeMax":60
      },
      "output":{  
         "val":2
      }
   },
   {  
      "id":"67ab2cda-ec00-4bea-900d-3f0736c48a71",
      "type":"faiz",
      "input":{  
         "pk":[  
            "00"
         ],
         "vadeMin":1,
         "vadeMax":60
      },
      "output":{  
         "val":35
      }
   },
   {  
      "id":"c4fb80b4-4697-482d-b0b0-7096b6769312",
      "type":"faiz",
      "input":{  
         "pk":[  
            "00"
         ],
         "vadeMin":1,
         "vadeMax":60
      },
      "output":{  
         "val":1
      }
   }
]

simonare avatar Feb 11 '19 12:02 simonare

Thanks for contacting us, @simonare. Can you please provide a more comprehensive example? The JSON you've shared above doesn't map with the screenshot above so it's not clear really how you envision this to work.

mkArtakMSFT avatar Feb 11 '19 20:02 mkArtakMSFT

Hi. We're closing this issue as we have heard no response from you for some time now. If you have more details and are encountering this issue please add a new reply and re-open the issue.

mkArtakMSFT avatar Apr 17 '19 21:04 mkArtakMSFT