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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:03:56+00:00 2026-05-25T13:03:56+00:00

i am having a problem while retrieving the data coming from Json… i am

  • 0

i am having a problem while retrieving the data coming from Json…

i am passing some values through $.ajax and i want to process that values in the controller..

please help, how can i retrieve the values in controller…

Jquery Code

    var userID = @Model.User.UserID;
        var postID = @Model.Post.PostID;
        var commentBody = $('#textareaForComment').val();

$('#btnSubmit').click(function (e)
    {

        e.preventDefault();
        var postdata = 
        {
            CommentBody: commentBody,
            PostID: postID,
            UserID: userID            
        };

        $.ajax({
            url: '@Url.Action("SubmittedComment","Post")',
            data: postdata,
            success: function(data) { 
                $('#showComments').html(data);
            }
        });
  });

now i am calling the SubmittedComment Action in the Post controller and i want to have the PostID,USerID and the CommentBody in that action and want to store it in a diff variable..

please help. thx

controller code

public JsonResult SubmittedComment(string CommentBody,UserID,PostID)
        {

            var result = CommentBody // i am not able to get the value here ....

        }
  • 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-25T13:03:57+00:00Added an answer on May 25, 2026 at 1:03 pm
    $('#btnSubmit').click(function () {
        $.ajax({
            url: '@Url.Action("SubmittedComment","Post")',
            // Values should be evaluated at the callback, not at page load time
            // this is not the case for UserID and PostID, but for CommentBody it is
            data: {
              UserID: @Model.User.UserID,
              PostID: @Model.Post.PostID,
              CommentBody: $('#textareaForComment').val()
            },
            success: function(data) { 
                // Controller action returns data in Json format, so .html() makes no sence here.
                // Change action to return html markup via PartialView or change this function to
                // parse Json. Also, returning Json via GET request is forbidden by default by ASP.NET MVC (just in case you don't know
                $('#showComments').html(data);
            }
        });
        return false; // Equals to e.preventDefault()
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having a problem while encrypting some data in the file. i'm using simple
I am having a problem while doing some XSLT pre-processing in my java program.
Having a problem while passing messages using content scripts in Google chrome extension dev
I am having a problem while sending mails through code.Actually the code is running
I'm having a problem while trying to call a custom Model method from my
I'm having problem from a while (since I'm using visual studio 2010 I think).
I am having a problem retrieveing information from a MySQL Data Base. Could you
I have a flash file menu i am having problem while link it to
I am having problems while saving a pre-persisted JDO object in google-app-engine data store.
I'm having some trouble getting my cache to work the way I want. The

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.