I created a small working sample for you (see solution below). It mainly depends on how you create your client object.
Model -
public class trans { [Key] public int tID { get; set; } public virtual Location Location { get; set; } } public class Location { public int locID { get; set; } }
Controller Actions -
public ActionResult Index() { return View(); } [HttpPost] public JsonResult Submit(trans trans) { return null; }
Simple view -
@{ ViewBag.Title = "Home Page"; } <table id="example" class="display"> </table> @section scripts{ <script> $(function() { var o = new Object(); o.tID = 123; o.Location = new Object(); o.Location.locID = 456; $.ajax({ url: '@Url.Action("Submit", "Home")', type: "POST", cache: false, data: JSON.stringify({ trans : o }), contentType: "application/json; charset=utf-8", success: function(data) { if (data) { alert("Success"); } }, error: function(jqXhr, textStatus, errorThrown) { alert(errorThrown); } }); }) </script> }
When you start the page, it will hit the controller post-installation and check the output file below -

source share