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

139
Views
I am passing data from view to conntroller using ajax method call but data becomes null when it comes to action method
function UserLogin() {

        var username = $("#txtUsername").val();
        var passcode = $("#txtPassword").val();
        alert(username);

        $.ajax({

            url: '@Url.Action("Login", "UserAccount")',
            type: "POST",
            data: { 'username': username, 'passcode': passcode },
            datatype: "json",
            traditional: true,
            contentType: "application/json; charset=utf-8",
            success: function (data) {
                alert(data.username);

        }
    });

[HttpPost] public ActionResult Login(string username, string passcode) { if (IsValidUser(username, passcode)) { return RedirectToAction("UserInfo", "UserAccount"); } else { ModelState.AddModelError("", "Your Username or password is invalid"); } return View(); }

    private bool IsValidUser(string username, string passcode)
    {
        string Query = "Select Count(ID) from Users where Username =" + username + " and PassCode = "+ passcode +"";
        int count = Convert.ToInt32(NpgSQLHelper.ExecuteScalar(Utility._connectionstring, System.Data.CommandType.Text, Query));
        if (count > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Remove the contentType: "application/json; charset=utf-8" or modify contentType to contentType:"application/x-www-form-urlencoded" can work fine.

about 4 years ago · Juan Pablo Isaza 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!