0

I have tried several different ways to try and call an MVC 4 controller method almost all of them have been 404s.

ive also looked at many different posts and websites trying to get it to work but i have had no success my controller looks like this

public class AjaxController : Controller
{

    public ActionResult AjaxContactForm()
    {
        Data.DataUtilities.ForwardCustomerEmail();
        var pause = "";
        var result = "";
        return Json(result);
    }

}

the path of the controller is Portfolio(root)\Controllers\AjaxController.cs

almost every url that i have tried results in a 404

this is what i have currently

var params = {
             conName: contactName,
             conEmail: contactEmail,
             conMessage: contactMessage
             };
$.ajax({
    url: '<%:Url.Action("AjaxContactForm","AjaxController") %>',
    type: "post",
    success: function () {

    }
  });

ive tried

'<%:Url.Action("AjaxContactForm","Controller/AjaxController") %>'
'<%:Url.Action("AjaxContactForm","/Controller/AjaxController") %>'
'<%:Url.Action("AjaxContactForm","/Controllers/HomeController.cs") %>'
'/AjaxController/AjaxContactForm'
'Controller/AjaxController/AjaxContactForm'
'/Controller/AjaxController/AjaxContactForm'

ive done all these as well using a $.post but i can never hit the method.

what am i doing wrong

1 Answer 1

2

It should be

Url.Action("AjaxContactForm","Ajax")

AjaxController should be referenced as "Ajax".

HomeController should be referenced as "Home".

etc.

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

1 Comment

well that makes perfect sense and absolutely no sense at all, lol thanks for your help

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.