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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:58:47+00:00 2026-06-12T09:58:47+00:00

First post, please be gentle :) I am relatively new to MVC3 and am

  • 0

First post, please be gentle 🙂

I am relatively new to MVC3 and am building a webapp at work.

I have several pages with CheckBoxes that turn features on/off and when they change I submit via a jQuery Ajax call and return a json success/fail to me so I can display a message.

I have some forms with a bunch of fields that I was just submitting (not with Ajax) and checking if the modelstate is valid etc.. and redisplaying the form with messages if not. I want to do this using Ajax instead.

I have a form using Ajax.BeginForm which submits properly to the controller, the model is validated and if it has errors, i return a partial view which is replaced using the UpdateTargetId.

The thing I want to do is this… If the model was valid and the save successful, I need to return a partial view nonetheless because the UpdateTargetId will replace my form no matter what. I would like to send back a ‘success’ flag of some kind so I can then display a message to say ‘your data was saved’ or something.

OnSuccess fires if the Ajax call was successful, and doesn’t care if the model was valid.

I could use jQuery.Ajax to submit the form and in the controller return the return the PartialView as well as a success or fail I think?

Can anyone tell be what the best practices are when building ‘Ajax’ web apps?

  • 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-12T09:58:49+00:00Added an answer on June 12, 2026 at 9:58 am

    You may use plain javascript instead of using the Ajax.Beginform helper method to handle this.

    @model ProductViewModel
    <div id="divForm">
    @using(Html.Beginform())
    {
      @Html.TextBoxFor(x=>x.Name)
      @Html.TextBoxFor(x=>x.Location)
      <input type="submit" id="btnSave" />
    }
    </div>
    <div id="divItem" />
    <script type="text/javascript">
      $(function(){
        $("#btnSave").click(function(e){
             e.preventDefault();   // prevent the default form submit
    
             var form=$(this).closest("form");
             $.post(form.attr("action"),form.serialize(),function(result){
                if(result.Status=="success")
                {
                  //show message and load the new partial view if needed.
                  $(#divForm").hide();
                  $("#divItem").html(reuslt.ViewHTML);
                }
                else
                {
                   alert("Error");
                }
             });
        });
      });
    </script>
    

    Assuming you have an HttpPost action method which accepts our form subimt and return JSON data back.

    [HttpPost]
    public ActionResult Edit(ProductViewModel model)
    {
      // here you may validate the model and save if needed and return JSON back.
      //to do  : return JSON
    }
    

    Response JSON should be in the below format.

    { "Status" : "success", "ViewHTML" : "<p>This is some markup</p>" }
    

    This answer explains how to return ViewResult in JSON response.

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

Sidebar

Related Questions

My first post here, please be gentle. =) I work for a company that
this if my first post so please be gentle. I have an iOS 5
This is my first post on StackOverflow, so please be gentle... I have some
This is my first post, so please be gentle. I've been playing around with
This is my first post, so please be nice :) I have a question
This is my first post on this forum (so please be gentle ) I'm
First post, please be kind. NOTE: I have reviewed entry #20856 (how to implement
this is my first post so please show some understanding. I have some java
thats my first post, so please be kind. I have a matrix with 3~10
My first post to Stack Overflow so be gentle please! I am about to

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.