KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a controller action whose definition looks like- public ActionResult ChangeModel( IEnumerable<MyModel> info, long? destinationId) And the model: public class MyModel { public string Name; //Gets populated by default binder public long? SourceId; //remains null though the value is set when invoked } The 'Name' property gets populated in the controller action however the SourceId property remains null. The destinationId which is a long? parameter gets populated as well. While stepping through the MVC (version 2) source code this is the exception thrown by DefaultModelBinder. The parameter conversion from type 'System.Int32' to type 'System.Nullable`1[[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' failed because no type converter can convert between these types. If the model is changed to long instead of long?, the default model binder sets the value. public class MyModel { public string Name {get;set;}; //Gets populated by default binder public long SourceId {get;set;}; //No longer long?, so value gets set } Is this a known issue? Since the MVC source code is optimized, I am not able to step through most of the code. Update: The request being sent is a Http POST using Json with the source JSon resembling - {"info":[{"Name":"CL1","SourceId":2}], "destinationId":"1"}
Tags (comma-separated)
Save Edits
Cancel