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

173
Views
POST FormData object to Razor Page

I have an issue with a simple jQuery $.post in my application. I have tried many methods and solutions on the internet to no avail. When post request is sent I see 400 error

public class RecoveryAdhocInvoicingModel : PageModel
{                                                                                  
    Public IActionResult OnPostDoJob(string invNo, string account)
    {
        //var emailAddress = Request.Form["emailaddress"];
        // do something with emailAddress
        return new JsonResult("");
    }                                                                                   
}

In my script the $.post method is called via button click:

$('#submitBtnUpdateJob').click(function (evt) {
            var formdata = new FormData();
            formdata.append("invNo", $('#adhocInvoiceNumber').val());
            formdata.append("account", $('#invoiceAccountInput').val());

    $.post(window.location.href + '?handler=DoJob', JSON.stringify(formdata), function () {
         alert('Posted');
    });                                                                                   
});

Solution folder path

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to add the RequestVerificationToken header to the request.

$.ajax({
    type: "POST",
    headers: { "RequestVerificationToken": $('input[name="__RequestVerificationToken"]').val() },
    url: window.location.href + '?handler=DoJob',
    data: {
        "invNo": $('#adhocInvoiceNumber').val(),
        "account": $('#invoiceAccountInput').val()
    },
    contentType: "application/x-www-form-urlencoded"
}).done(function (response) {
    alert('Posted');
});

Documentation: https://www.learnrazorpages.com/security/request-verification#ajax-post-requests-and-json

almost 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!