I want to pass data between my view and my controller. I'm doing something wrong because it doesn't work.
JavaScript Front-end Code:
$.ajax({
url: '@Url.Action("GetOid","SearchPerson")',
data: {oid : 1},
type: 'POST',
contentType: 'application/json; charset=utf-8',
success: function (data) {
// return values
console.log("Success!" + data.oid);
},
error: function () { console.log('error!!'); }
});
C# Controller Code:
int CustomerId=0;
[HttpPost]
public ActionResult GetOid(int Oid)
{
// some code here to assign the value to a global var.
CustomerId = Oid;
ViewBag.id = Oid;
return Json(new { oid = CustomerId });
}
});