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

  • SEARCH
  • Home
  • 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 7407957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:49:19+00:00 2026-05-29T05:49:19+00:00

I am just exploring asp.net mvc as I want to switch from Webforms. I

  • 0

I am just exploring asp.net mvc as I want to switch from Webforms. I was just experimenting by trying to post a string using jQuery and getting that string back in the response. However, I am not sure how to access the the post parameter within the action method of the controller.

I tried using the FormCollection but it is empty (which I guess is obvious since I am posting using a jQuery ajax call and not a form)

 $(function () {
        $("#GetReport").click(function () {
            $.ajax({
                type: 'POST',
                url: '/Reports/GetReport',
                data: 'Abracadabra Mercedes',
                contentType: 'application/text;charset=utf-8',
                dataType: 'text',
                success: function (result) {
                    alert(result);
                }


            });
        });
    });

//Controller Code
public class ReportsController : Controller
    {
        //
        [HttpPost]
        public ActionResult GetReport(string query)
        {


            ViewBag.Result = "Hello";

            ViewBag.Geronimo = query;

            return View();

        }

    }

        //View Code
@{
    Layout = null;
}

@ViewBag.Result + @ViewBag.Geronimo
  • 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-29T05:49:20+00:00Added an answer on May 29, 2026 at 5:49 am

    Your ‘data’ needs to be a list of key/values like on a URL. Then you will get that information coming through into the query param of your Action method.

    e.g.

    $(function () {
        $("#GetReport").click(function () {
            $.ajax({
                type: 'POST',
                url: '/Reports/GetReport',
                data: 'query=Abracadabra Mercedes',
                success: function (result) {
                    alert(result);
                }
    
    
            });
        });
    });
    

    see http://www.tugberkugurlu.com/archive/working-with-jquery-ajax-api-on-asp-net-mvc-3-0-power-of-json-jquery-and-asp-net-mvc-partial-views for more information.

    In that example you can see he is doing this. Look for:

    var d = "itemId=" + itemId;
    

    Edit: I just tried here now

    <input type="button" value="Click" id="GetReport" />
    <input type="text" id="tester"/>
    
    <h2>Index</h2>
    <script type="text/javascript">
    $(function () {
        $("#GetReport").click(function (e) {
            var d = "input=" + $('#tester').val();
            debugger;
            $.ajax({
                type: 'POST',
                url: '/Home/test',
                data: d,
                success: function (result) {
                    alert(result);
                }
    
            });
    
            if (e && e.preventDefault) {
                e.preventDefault();
            }
        });
    });
    

    and

    public class HomeController : Controller
    {
        [HttpPost]
        public ActionResult Test(string input)
        {
            return new ContentResult() { Content = input };
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am exploring ASP.NET MVC and I wanted to add jQuery to make the
I'm trying to call an ASP.NET .asmx webservice, from javascript, using other than the
I am creating my first ASP.NET MVC 3 application, and my data comes from
I just started learning ASP.NET and HTML5, and looking for experts inputs. I'm exploring
When coding up Ajax calls in ASP.Net MVC we have a lot of options
We've recently hired a design/ui/accessibility guy to give our asp.net MVC app a coat
We are working on an ASP.NET MVC 3 project and taking advantage of Razor
I wanted to get your opinion about managing scripts in ASP .NET MVC. There
I've implemented a custom ASP.NET session timeout control derived from a control by Kenneth
I am starting to learn ASP.NET MVC. I have deployed the stock ASP.NET MVC

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.