I am using MVC3 and that i know MVC3 support binding JSON literal to Action parameter. But i can't do it successfully;
I have a class name Tag
public class Tag
{
public int tagId { get; set; }
public string tagName { get; set; }
}
An Action on controller called Tag
[HttpPost]
public ActionResult Tag(Tag tag)
{
// Here will be codes...
return Json(new { success = 0 });
}
Javascript code that send js object as JSON to my action
var tag ={tagId:5,tagName:"hello"};
$.ajax({
url: "/image/tag",
type: "POST",
data: $.toJSON(tag),
success: function (r) {
if (r.success == 1) {
window.location = r.redirect;
}
}
Post Data that I see in Firebug Net tab
{"tagId":5,"tagName":"hello"}
Parameter name tag in Tag Action is not null but has values O for tagId and null for tagName. What the problem in here?