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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:33:33+00:00 2026-05-28T14:33:33+00:00

Here is my ajax call $.ajax({ type: POST, url: MyMethod, contentType: ‘application/json; charset=utf-8’, data:

  • 0

Here is my ajax call

$.ajax({
            type: "POST",
            url: "MyMethod",
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify({  Param1: 'value1', Param2: 'value2'}),
            success: function (msg) { location.href = '@Url.Action("MyActionMethod", "MyController")'; },
            error: function (msg) { alert(msg); }
        });

This is my model

public class MyModel
{
    public string Param1 { get; set; }
    public string Param2 { get; set; }
}

MyMethod implementation is as follows

public bool MyMethod(MyModel model)
{

    if (!ValidateModel(model) )
    {
        // I want to error a descriptive error  
        return false;
    }

    // Some other processing
    return true;
}

Problem is that I don’t know how does it determine if call is a success or failure. Returning ture/false does not seem to help as code always go in the success code path (that is it redirects to MyController.MyActionMethod). Any ideas what i am doing wrong

  • 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-28T14:33:33+00:00Added an answer on May 28, 2026 at 2:33 pm

    This is usually what I do:

    public JsonResult MyMethod(MyModel model)
    {
        var success = true;
        var result = string.Empty;
    
        if (!ValidateModel(model) )
        {
            // I want to error a descriptive error  
            success = false;
            result = "Invalid model";
        }
    
        // Some other processing
        return Json(new { success = success, error = result }, 
            JsonRequestBehavior.Allow);
    }
    

    Note the change in the return method from bool to JsonResult. And then in your JavaScript you could test the properties coming through on the JSON object:

    ...
    success: function (msg) { 
       if (msg.success) {
           location.href = '@Url.Action("MyActionMethod", "MyController")'; 
       } else {
           alert(msg.error);
       }
    },
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery .ajax call: $j.ajax({ type: POST, url: /Services/Cart.asmx/UpdateQuantity, data: data, contentType:
Here is my AJAX call: $.ajax({ type: 'POST', url: '<?php echo site_url('channel_partners/cms/get_news'); ?>', data:
I have the following code: $.ajax({ type: POST, url: url, data: sendable, dataType: json,
I have this ajax call at the moment: $.ajax({ url: misc/sendPM.php, type: POST, data:
I have a simple ajax call like this: $.ajax({ url: u, type: POST, dataType:
After doing so: $.ajax({ type: POST, url: $(#form).attr(action), data: value= + value + &sel=
I have following ajax call: $(#container).html(loading...); $.ajax({ url: somedoc.php, type: POST, dataType: html, success:
$.ajax({ async:false, type: 'POST', url: itemURL, success: function(data,status,jqXHR) { responseObj = data; console.log('success function
Here is my AJAX call: $(document).ready(function () { $(#btnSignup).click(function () { $.ajax({ type: POST,
I'm have trouble grabbing the response JSON data that's returned via AJAX call. Here

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.