Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:39:54+00:00 2026-06-09T11:39:54+00:00

I’m trying to make an AJAX call to a model that I have in

  • 0

I’m trying to make an AJAX call to a model that I have in my MVC project. I keep receiving the following error:

POST foobar/GetDate 405 (Method Not Allowed)

(Where ‘foobar’ is my localhost:port format for the MVC project.)

I haven’t played around with routing in the project yet, as I’m not sure what a route to a script should look like. I know how to properly route views at this point. Here are some code snippets:

In my MVC Project, I have a Model with the following method:

[WebMethod]
public static string GetDate()
{
    return DateTime.Now.ToString();
}

In my Index.aspx file, I have this code:

<button class="getDate">Get Date!</button>
<div class="dateContainer">Empty</div>

And in my script.js file, I have this code:

$.ajax({
    type: "POST",
    url: "GetDate",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (msg) {
        // Replace text in dateContainer with string from GetDate method
        $(".dateContainer").text(msg.d);
    },
    complete: function (jqHXR, textStatus) {
        // Replace text in dateContainer with textStatus
        if (textStatus != 'success') {
            $(".dateContainer").text(textStatus);
        }
    },
});

My end goal is to send XML data to my method in the C# model, then parse and save the XML document.

Right now, I’ll settle on trying to link up the AJAX request in jQuery to the C# method I have. I’m positive it has something to do with routing and syntax.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:39:55+00:00Added an answer on June 9, 2026 at 11:39 am

    Why do you have an [WebMethod] method in an MVC Project ?

    In MVC, you can have action methods in your controllers. You can call this from ajax as well

    public class WebController : Controller
    {
        public ActionResult GetDate()
        {
           return Content(DateTime.Now.ToString());
        }
    }
    

    You can call it from your javascript like this (with jQuery)

    $.get("@url.Action("GetDate","Web")",function(result){
         alert("The result from ajax call is "+result);
    });
    

    If you are doing a POST call to the method, make sure to decorate your action method with POST attribute.

        [HttpPost]
        public ActionResult SaveUser(string userName)
        {
           //do something and return something
        }
    

    You can even return JSON from your action method to your ajax call’s callback function. There is a JSON method in Controller (the base class of our WebController) class to do this.

        public ActionResult GetMagician(string userName)
        {
           return Json(new { Name="Jon", Job="Stackoverflow Answering" },
                                      JsonRequestBehavior.AllowGet);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I am trying to loop through a bunch of documents I have to put
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.