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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:14:20+00:00 2026-06-04T08:14:20+00:00

I call a controller action using jquery ajax (see the below code), After the

  • 0

I call a controller action using jquery ajax (see the below code), After the action has been executed, An Invalid Json error was raised. And I’ve notice that, it returns the page content. Why did it happen. can Anyone help me to solve this problem?

Controller

[HttpGet]
       public ActionResult ViewDetails(int id)
       {
           var eventsdetails = _service.GeteventByID(id);
           return View("EventDetails",eventsdetails);
       }


       [HttpPost]
       public ActionResult UpdateAnswers(string answers, string question, string controlid, int eventid)
       {
           var replacetext=string.Empty;
           if (answers.Length>0) 
             replacetext = answers.Replace("\n", ",");
           _service.UpdateAnswers(eventid, replacetext, controlid);
          return RedirectToAction("ViewDetails", new { id = eventid });
       }

Javascript

function dropdownlist(controlid, title, answers, eventid) {
            var $answersreplaced = answers.replace( /\,/g , " \r");
            var $deleteDialog = $('<div><textarea id="answerlist"  rows="10" cols="50">' + $answersreplaced + '</textarea><div><div style="font-size:9px">(To change back to an open answer field, delete all choices above and save)</div>');
            $deleteDialog.dialog({
                resizable: false,
                height: 280,
                width: 350,
                title: title + " - Edit Choices",
                modal: true,
                buttons: {
                    "Save": function () {
                        $.ajax({
                            type: 'POST',
                            url: '@Url.Action("UpdateAnswers")',
                            dataType: 'json',
                            data: { answers: $('#answerlist').val(),
                                question: title,
                                controlid: controlid,
                                eventid: eventid
                            },
                            success: function (result) {
                                $(this).dialog("close");
                                alert(result);
                            },
                            error: function (xhr, ajaxOptions, thrownError) {
                                alert(thrownError);
                                // alert('there was a problem saving the new answers, please try again');
                            }
                        });
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }
                }
            });
        };
  • 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-04T08:14:21+00:00Added an answer on June 4, 2026 at 8:14 am

    It’s because you’re not returning a JsonResult from the action, you’re redirecting to another action, which in turn returns a ViewResult.

    Try something like this:

    [HttpPost]
    public ActionResult UpdateAnswers(string answers, string question, string controlid, int eventid)
    {
        var replacetext=string.Empty;
        if (answers.Length>0) 
            replacetext = answers.Replace("\n", ",");
        _service.UpdateAnswers(eventid, replacetext, controlid);
        var eventsdetails = _service.GeteventByID(eventid);
        return Json(eventdetails);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call the 'tariff' action of my 'countries' controller using jQuery ajax()
I am using jquery ajax call and in controller action i want to redirect
if i call a ajax request using jquery to an asp.net mvc controller action
I am using an Ajax.ActionLink to call an Action in a Controller, nothing special
I am trying to achieve a JQuery AJAX call to a controller action method
How can I call a ViewResult controller action/method from jquery/javascript using something similar to
Using JQuery's ajax() or get() methods we can make an async call to the
I have an AJAX controller action which returns JSON. The returned JSON is handled
I am trying to call a controller action from a jquery UI dialog. What
In the below 'simple' Ajax login example, I'm using JQuery to submit form params

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.