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 6635395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:02:55+00:00 2026-05-25T23:02:55+00:00

I just copied some code from an asp.net mvc 2 app which works. Now

  • 0

I just copied some code from an asp.net mvc 2 app which works. Now i am trying it in asp.net mvc 3 and it does not call the save method on the controller?

controller:

 [HttpPost]
    public JsonResult save(string inputdata)
    {
        return Json(new { Result = string.Format("From the controller - you have clicked the GO-button ! ") }, JsonRequestBehavior.AllowGet);
    }

view:

<button id="but">go</button>
<div id=result></div>
<script type="text/javascript">

    $(document).ready(

    $("#but").click(
        function () {
            $.ajax({
                url: "/Home/save",
                dataType: "json",
                type: 'POST',
                data: "test",
                success: function (result) {
                    $("#result").html(result.Result);
                }
            });

        }
    )

    );

</script>
  • 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-05-25T23:02:56+00:00Added an answer on May 25, 2026 at 11:02 pm

    You are not passing the data correctly. The action argument is called inputdata. So you should use this same name in the data hash of the AJAX request:

    $.ajax({
        url: '/Home/save',
        dataType: 'json',
        type: 'POST',
        data: { inputdata: 'test' },
        success: function (result) {
            $('#result').html(result.Result);
        }
    });
    

    Also never hardcode urls in your javascript, always use url helpers or your application will simply stop working when you deploy due to the possibility of having a virtual directory name:

    $.ajax({
        url: '@Url.Action("save", "home")',
        dataType: 'json',
        type: 'POST',
        data: { inputdata: 'test' },
        success: function (result) {
            $('#result').html(result.Result);
        }
    });
    

    Another issue that you have with your code is that you are not canceling the default action of the button meaning that if this is an action link or a submit button the AJAX request might never have the time to execute before the browser redirects.

    Also you don’t need to specify the dataType to JSON as jQuery is intelligent enough to deduce this from the Content-Type response header sent from the server.

    So the final version should look something along the lines of:

    <script type="text/javascript">
        $(function() {
            $('#but').click(function () {
                $.ajax({
                    url: '@Url.Action("save", "home")',
                    type: 'POST',
                    data: { inputdata: 'test' },
                    success: function (result) {
                        $('#result').html(result.Result);
                    }
                });
                return false;
            });
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently, I was trying to prototype some jQuery-based menu into ASP.NET MVC. Just to
just wondering if anyone knows of a truly restful Put/delete implementation asp.net mvc preview
I have an HTML file, just with the AdMob code (exactly copied from AdMob
I just copied this code from the MIT video lecture that is posted online:
i have copied this code from the FB.init documentation : <script src=http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US type=text/javascript></script> ...
I've been trying to use http://livepipe.net/control/tabs to get some javascript tabs up and running
Working on a qt project using msvc2008 compiler. I copied some functions from an
I am currently experimenting with dynamically loaded areas with ASP.NET MVC 3 RC. I've
The code below works on one page, but not another page (the place it
Possible Duplicate: How to prevent your JavaScript code from being stolen, copied, and viewed?

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.