0

I have a response 404 from controller on submit simple form.

javascript:

var FunctionName= function () {
var form = $("#formId").serialize();
form.validate();
if (form.valid()) {
    $.ajax({
        url: "/Cliente/Register",
        data: form,
        type: "POST",
        success: function (data) {
            if (data.success) {
                //todo
            }
            else {
                //todo
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            $(".LoginMessage").html("Erro");
            alert("Status: " + textStatus); alert("Error: " + errorThrown);
        }
    });
}

}

Controller:

[HttpPost]
    public JsonResult Register(FormCollection values)
    {...}

When I remove the action filter "[httpPost]" the system finds the method, someone help me please...

4
  • 404 is Not found error. That means he cannot find /Cliente/Register. make sure url is written correctly Commented Feb 11, 2017 at 16:02
  • I know what 404 is. What I do not understand is because it is occurring because the url is right. Commented Feb 11, 2017 at 16:07
  • can you add add (ActionName=Register) with [HttpPost] and try again? Commented Feb 11, 2017 at 16:45
  • Doesn't work....The request "found" the method...but while the method executing, the page 404 show. Commented Feb 11, 2017 at 19:12

2 Answers 2

2

Change

type: "POST",

To

method: "POST",

"method" is the property where you set the type of your request. Since you have not specified it, it's taking its default value "GET". Thats why if you remove the action filter, the method is found.

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

Comments

0

I think you are misspelling your URL.

Change this:

url: "/Client/Register",

To

url: "/Client/Register",

There is an extra "e" letter at the end of the word "Client".

Comments

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.