Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

354
Views
Jquery ajax not passing parameters to controller method in Asp.Net Core MVC

I am using the following code for calling the controller method ans passing the parameters. The Method is getting called but values are coming null in controller method.

The same code is working fine in MVC 4 project, but in Asp.Net Core MVC it is not working.

var UserModel = {
  "FName": "Abc",
  "LName": "Pqr"
};
$.ajax({
  url: 'http://localhost:60600/Home/AddUser/',
  type: "POST",
  contentType: 'application/json; charset=utf-8',
  dataType: "json",
  data: JSON.stringify(UserModel),
  success: function () {
  }
});
public class HomeController : Controller
{
  // GET: /<controller>/
  public IActionResult Index()
  {
    return View();
  }

  // [HttpPost]
  // [AllowAnonymous]
  public IActionResult AddUser(UserModel model)
  {
    //  Add user model
    return Json("");
  }
}

public class UserModel
{
  public string FName { get; set; }
  public string LName { get; set; }
}
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

you can try it like this

var UserModel =
{
    FName: "Abc",
    LName: "Pqr"
};
$.ajax({
    url: '/Home/AddUser/',
    type: "POST",
    //contentType: 'application/json; charset=utf-8',
    dataType: "json",
    data: UserModel,
    success: function () {

    }
});
about 4 years ago · Santiago Trujillo Report

0

Please remove JSON.stringify

var UserModel = {
  "FName": "Abc",
  "LName": "Pqr"
};
$.ajax({
  url: 'http://localhost:60600/Home/AddUser/',
  type: "POST",
  contentType: 'application/json; charset=utf-8',
  dataType: "json",
  data: UserModel,
  success: function () {
  }
});
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!