1

My folder structure looks like this. Both of these folders are contained within the Area folder.

Folder structure

I am trying to call a function from the EmailController inside ITRequests/Scripts/Edit.js and it fails to find it. The .js code look likes this

$(document).on('change', '#StatusId', function (event) {
    event.preventDefault();
    debugger;
    if(( $('#OldStatus').val() ) != ( $('#StatusId').val()) ) //Aka if the user switched the status on submit
    {
        var status_description = [$('#OldStatus').val(), $('#StatusId').val()];
        $.ajax({
            url: "/Email/Email/statusChangeEmail",
            type: 'POST',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify({ 'request': $('#RequestId').val(), 'status_descriptions': status_description }),
            done: function (data) {
                debugger;
                alert("working");
            }
        })
    }
})

RequestId is a hidden value on the page which is being picked up correctly, likewise the status_description field is taking the correct values and (tries to) pass them to the function. The function EmailController.cs is defined as such

[HttpPost]
    public ActionResult statusChangeEmail(int request, string[] status_descriptions)
    {
         //stuff happens
         return Json(1);
    }

However every time this happens I get this error messageenter image description here

2
  • 1
    Can you try url: "/Email/statusChangeEmail" Commented Jul 28, 2016 at 13:26
  • 1
    You have 1 too many Email in your url. Commented Jul 28, 2016 at 13:28

1 Answer 1

1

Why your URL is /Email/Email/statusChangeEmail? It should be /Email/statusChangeEmail.

The /Email means EmailController and /statusChangeEmail means controller action statusChangeEmail .

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

2 Comments

Wow that was an easy fix. I named it as such because the function calls to ITRequstsController functions are done in the same way. i.imgur.com/3lVBGW7.png why is it that these functions have ITRequests/ITRequests before the function name and still work?
You can read more about routing in asp.net/mvc/overview/controllers-and-routing. Basically you can have any value to be routed to a URL.

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.