2

Got that error while try to call my controller's method (controller's name is ProductsController):

public ActionResult GetProducts()
{
    return false;
}

Calling code like this:

$(document).ready(function () {
        $.ajax({
            type: 'POST',
            url: '@Url.Action("GetProducts", "ProductsController")',
            dataType: 'json',
            cache: false,
            contentType: 'application/json; charset=utf­8',
            data: JSON.stringify(""),
    })

Console in Chrome says:

jquery-1.10.2.js:8720 POST http ://localhost:56408/ProductsController/GetProducts 404 (Not Found)

Do you have any idea what is the problem?

1
  • 2
    Just use the controller name prefix Products instead of ProductsController Commented Aug 6, 2016 at 14:34

1 Answer 1

2

Use the controller name prefix Products instead of ProductsController

$(document).ready(function () {
    $.ajax({
        type: 'POST',
        url: '@Url.Action("GetProducts", "Products")',
        dataType: 'json',
        cache: false,
        contentType: 'application/json; charset=utf­8',
        data: JSON.stringify(""),
});

Asp.Net-MVC uses a naming convention for controllers.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you very much!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.