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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:19:28+00:00 2026-06-07T20:19:28+00:00

Setup: ASP.NET MVC3, jQuery, C# Has anyone got a clean solution to handle different

  • 0

Setup:
ASP.NET MVC3, jQuery, C#

Has anyone got a clean solution to handle different partial views returning from the same action method? One for the next stage, one for returning the view again with validation errors and the other for display an unhandled exception.

I have a controller method that does something like:

public ActionResult SomeMethod(MyModel model)
{

    if(_service.Validate(model))
    {

    if(_service.Update(model))
    {
        // return next view once success
                return PartialView("EverythingIsGood"); // This should be pushed into #somediv  
    }else{
        throw new HardException("Tell the client something bad has happened");
    }
    }
    else
    {
    // Return the same view to highlight the validation errors
        HttpContext.Response.StatusCode = 500;
    return PartialView("SomeMethod", model); // This should be pushed into #anotherdiv  
    }

}

Client Script

 $.ajax({
        url: baseUrl + "Home/SomeMethod",
        type: "GET",
        success: function (data) {
            $("#somediv").html(data);
        },
        error: function (data) {
            handleError(data);
        }
    });

I guessing I need something like softerror:

  $.ajax({
        url: baseUrl + "Home/SomeMethod",
        type: "GET",
        success: function (data) {
            $("#somediv").html(data);
        },
        softerror: function (data) {
            $("#anotherdiv").html(data);
        },
        error: function (data) {
            handleError(data);
        }
    });

I was thinking of maybe returning a different status code for the soft validation errors but this feels hacky.

  • 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-07T20:19:30+00:00Added an answer on June 7, 2026 at 8:19 pm

    You can pass one more variable in your response and check it value on client side via js.
    something like this:
    Controller:

    if(_service.Update(model))
    {
    return Json(new {
            IsEverythingGood=true;
                    htmlToShow=PartialView("EverythingIsGood"); // This should be pushed into #somediv
        });
    }
    

    …

    else
        {
              return return Json(new {
                IsEverythingGood=false;
                        htmlToShow=PartialView("SomeMethod", model); // This should be pushed into #anotherdiv  
        }
    

    and in your javascript:

    success: function (data) {
        if(data.IsEverythingGood==true){
            $("#somediv").html(data.htmlToShow);
        }
        else if(data.IsEverythingGood==false){
            $("#anotherdiv").html(data.htmlToShow);
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With an ASP.NET MVC3 WebGrid how can I setup the column sorting such that
How to setup web.config to see the complete error message for ASP .NET MVC3
I have a very simple asp.net mvc3 app that uses jquery::getJSON to call into
Using ASP.Net MVC3 with C# I have a rotating ad setup on my layout
I have setup an ASP.NET MVC3 website using Windows Authentication and am getting a
I have an ASP.NET MVC3 website setup using fluent validation and ninject. The validation
I have an ASP.NET MVC 3 application that uses the Ninject.MVC3 extension to setup
I've got webform routing setup on my asp.net webforms 3.5sp1 project. I would like
I am using jQuery 1.7.1 and jQuery maskedinput 1.3 in my ASP.NET MVC 3
I have published an ASP.NET MVC3 site. It runs great. However, looking back at

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.