Reputation: 41909
Working on MVC4 + jQuery software.
On my jQuery front-end/UI, I configured a "Go" button to:
data
objectdataToSend = JSON.stringify(data)
For the server-side Controller, I've noticed that there are methods (whose names match controller routes' actions) that contain argument inputs, such as int
or string
.
How does the client-side JSON gets converted into an int
or string
for the server-side Controller? Do I need to convert the JSON data in some way?
Upvotes: 0
Views: 224
Reputation: 289
No, you don't have to do anything special. The MVC model binder will work it's magic and do it's best to map your POST data to Action parameters (it will attempt to map them by name). You don't typically have to worry about doing the type conversion; the model binder will do that for you.
Here's an excellent primer on how the MVC model binder works OotB: http://dotnetslackers.com/articles/aspnet/Understanding-ASP-NET-MVC-Model-Binding.aspx
Upvotes: 2