I have a JS file that creates a JSON string that I stringify and post with AJAX call to the server, using Fiddler I can see the JSON is formatted correctly and my Action is called as it stops at the breakpoint but my Model has just Nulls.
Here is the JS code:
var testString = { id: "1", date: "28/04/2013", sim: "B787", times: "0100", note: "Test note" };
$.ajax({
url: url,
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(testString),
success: function (data) {
},
error: function (request, status, error) {
}
});
And here is the Model:
[Serializable]
public class BookingModel
{
public int Id { get; set; }
public DateTime Date { get; set; }
public string Sim { get; set; }
public string Times { get; set; }
public string Note { get; set; }
}
Finally here is the Action that is called.
[HttpPost]
//[ValidateAntiForgeryToken]
public ActionResult Booking(BookingModel BookingModel)
{
return Json(new { sucess = 0});
}
And during debug the BookingModel shows nothing but NULL's but as I mention abouve FIddler is showing the string as:
{"id":"1","date":"28/04/2013","sim":"B787","times":"0100","note":"Test note"}
I have been at this for 2 days now and I'm getting bald someone please help... It's driving me nuts.
Thanks.
Cliff.
EDIT*
Ok bit more info looks like it does work but what I have to do is on the first breakpoint if I hit F5 to continue to the action is called again and this time the data is present and correct.
So my question now is as it works on the second round trip to the server whay not on the first?
Thanks
Cliff.
Html.BeginForm("MyAction", "MyController", new{id = 1, date = "28/04/2013", sim = "B787"})