Do I have to do anything special to my controller action method to accept/bind data from a .ajax() call?
Controller Action -
public class TestController : Controller
{
public JsonResult GetTestJsonData(Metadata data)
{
return new JsonResult { Data = data };
}
}
JQuery Call -
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
url: "GetTestJsonData",
data: "{ data: {Name:'joe'}}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert("Name = " + msg.Name);
}
});
});
</script>
I would expect that this page would alert with the name 'joe'. I'm passing json data from the client to the controller action and the action passes it back to the client. This is just a simple example of what I'm trying to do.