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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:33:51+00:00 2026-05-27T04:33:51+00:00

I am working on a MVC project that is supposed to have one page

  • 0

I am working on a MVC project that is supposed to have one page only, with two zones. On one zone I have a Google Map with markers, and the second zone is populated with the selected marker’s details.

The details view has a button that when clicked should change the entire view into edit mode without refreshing the page or redirecting it. I have used two views, for details and edit and with the help of ajaxForm function I am switching back and forth between these two views. I’m adding the ajaxForm on documentready for edit view.

<script type="text/javascript"> 
    // wait for the DOM to be loaded 
    $(document).ready(function() { 
        // bind 'myForm' and provide a simple callback function 
        $('#currentDiv').ajaxForm(function(data) { 
            $('#currentDiv').html(data);
        }); 
    }); 
</script> 

The problem appears when on server-side an error appears while trying to save data from edit view and I want to return to the same edit view with the errors displayed. The ajaxForm handler is not added any more and even if the new values that will try to be saved are ok, the detail view is loaded in another page.

Unfortunately, the use of ajaxForm creates some other problems because I don’t have control over the cases when the ajax call fails.

Any ideas on how could I fix this? Is it some other solution to switch between those two views without using ajaxForm and without refreshing the page?

  • 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-27T04:33:51+00:00Added an answer on May 27, 2026 at 4:33 am

    I think there are a couple of different questions that you are asking.

    First off, you add jquery handlers to deal with the case when you get a 500 type error from the server.

    Something like the following. I suggest taking a look at the docs for more info.

    $(document).ajaxError(function(event,jqXHR,ajaxSettings,thrownError){
       if (jqXHR.status != 0){
             window.location = <error page>
        }
    }
    

    The second problem seems to stem around error handling of known errors (say invalid input). In this case I suggest the following workflow.

    1) User clicks on edit button, taken to edit screen
    2) User enters in data, use client side validation to do initial check
    3) User submits, user is then taken to the view screen and is shown a
    success or error message.

    The server response could look like:

    public ActionResult Edit(EditModel model){
       if (!ModelState.IsValid)
       {
         return Json(new {successful = false, message = "Failed.."});
       }
       ...
    }
    

    On the client side, your form callback should now handle the message and the fact it was successful or not. In my implementation, I used knockoutjs to create a “message” area that I could update and clear. (I created templates, etc).

    Remember to use client side validation for the easy field validation stuff…. This will save a trip back to the server.

    Yours could be quite simple, by popping up the message returned from the server.

    Lastly, document ready only fires when the original document is done loading, never again for an ajax call (at least that is my understanding). Just put that code that is the document.ready at the bottom of the edit page. It will fire after the html it is targeting has already been rendered.

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC 2 project that I'm working on and I'm wondering
I have a simple mvc project consisting of one table named Persons and that
I have an MVC 3 project that I am working on using Entity Framework
I have a project that has, amongst other things, one web application (mvc) and
background:Me and my coworkers are working on asp.net mvc project ... we have a
I'm working on MVC project and i using jQuery in view page to get
I am currently working on a project that consists of an ASP.NET MVC 2.0
I recently joined a team that is working on a ASP.NET MVC project.. they
I'm completely new to JQuery and MVC. I'm working on a pet project that
I am working on my first asp MVC project that will ultimately end up

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.