I am using JQuery Ajax to make a simple call to an ASP.NET MVC controller. Here is my code
function postdata(idno) {
console.log(idno);
$.ajax({
type: 'POST',
url: "/IM/GetMessages",
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify({ 'fUserId': idno }),
success: function (data) { /*CODE*/
});}
The controller looks like this
[HttpPost]
public ActionResult GetMessages(decimal? fUserId)
{
var list = WebUtility.IMMessages.Where(p =>
(p.ToUserId == Session.UserId && (!fUserId.HasValue || fUserId.HasValue && p.User == fUserId.Value)))
.OrderBy(p => p.CreatedDateTime)
.Select(p => new { MessageId = p.RecordId, MessageBody = p.Description1 });
return Json(list, JsonRequestBehavior.AllowGet);
}
The problem is that my data doesn't pass to my controller, "null" passes instead. how can I correct this issue? I am watching "idno" on console and everything seems to be OK.