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

180
Views
how to send array of object to server. Asp.Net Core 3.1 405 Method Not Allowed

I am trying to send array of object to web Api post ActionResult method. my array of objects looks like this

'[{"TitleFeature":"عنوان یک","ValueFeature":"مقداریک","IdProduct":"1"},{"TitleFeature":"عنوان یک","ValueFeature":"مقداریک","IdProduct":"1"}]'

enter image description here

my function JS looks like this

const uri = '/api/Feature/PostFeatures';
        const baseURL = window.location.origin;
        var dataFeature = getFeature();
        var features = JSON.stringify(dataFeature);

        $.ajax({
            contentType: "application/json",
            dataType: 'json',
            type: "POST",
            url: (baseURL + uri),
            data: features,
        });

my Controller.cs is looks like this

[HttpPost]
    [AllowAnonymous]
    public async Task<ActionResult<Feature>> PostFeatures([FromBody] List<Feature> features)
    {
        if (features != null)
            foreach (var item in features)
            {
                _context.features.Add(item);
            }
        await _context.SaveChangesAsync();

        return Ok();
    }

I use Role Based authorization and this is my role:

[Route("api/[controller]")]
[ApiController]
[Authorize(Roles = "admin")]
public class FeatureController : ControllerBase

how to fix error 405?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

The 405 error means that you have entered the URL but the http request does not match, so if there is no route attribute on your action method, you can try to change the ajax request address to .../api/Feature

about 4 years ago · Santiago Gelvez 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!