I'm passing an object from jQuery to a MVC3 Controller via a $.ajax POST. While debugging using Developer Tools, I can see the object I'm assigning to the ajax data property. The object contains properties whose value is null. When I debug the Controller, the properties which were null in the JS Debugger are now "null" (strings).
Why is this? What can I do to prevent this from happening?
C# Object
public class User
{
public string Name { get; set; }
}
Javascript Object
var user = {
Name: null
}
Controller Method
public JsonResult HelloWorld(User user) { .. some logic .. }
ajax Call
var data = user;
$.ajax({
url: '/Controller/HelloWorld/',
data: data,
type: 'post',
success: ...
error: ...
})