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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:36:16+00:00 2026-05-11T14:36:16+00:00

We want to perform some calculations on some values in a view…so when the

  • 0

We want to perform some calculations on some values in a view…so when the user enters a value in a input…we want to go back to the server…perform the calculations and ‘refresh’ the view with the new values…With the code as it is now, it enters the correct (…or at least the one I ask it to) controller action, correctly performs the calculations and returns the updated ViewData to the view. When I step thru the loop that builds the html for the view, the ViewData has the updated values, but when the View is displayed on the browser, the values have not changed…

Here’s the javascript

$('input.changeValue').change(function() {     $('body').css('cursor', 'wait');     var changedAmt = this.value;     var frmUpdate = $('form#frmUpdate').serializeArray();      fooSoldObj = new Object();     fooSoldObj.name = 'fooSoldAmt';     fooSoldObj.value = changedAmt;      frmUpdate[frmUpdate.length] = fooSoldObj;      $.ajax(             {                 type: $('form#frmUpdate')[0].method,                 url: $('form#frmUpdate')[0].action,                 data: frmUpdate,                 dataType: 'html',                 error: function(error) {                     alert('frmUpdate error' + error);                 }             }         );       setTimeout(function() {         $('body').css('cursor', 'default');     }, 0); }); 

Here’s what the html for the form frmUpdate looks like

<form action='/Forecast/Update' id='frmUpdate' method='post' name='frmUpdate'>     <span>         <input id='HiddenForecastID' name='HiddenForecastID' type='hidden' value='XXX' />         <input id='HiddenForecastYear' name='HiddenForecastYear' type='hidden' value='2009' />         <input id='HiddenForecastMonth' name='HiddenForecastMonth' type='hidden' value='3' />            </span> </form> 

Now just to confuse things further, the data that is not displaying correctly is in a different form on the view. The reason (right or wrong) I have two forms is that the other form on the view kicks off a save routine.

Here’s the relevant part of the controller action

 [AcceptVerbs(HttpVerbs.Post)]     public ActionResult Update(FormCollection frmUpdate)                 {         //go off and do some stuff...this part works as the ViewData          //is correct....meaning it has the updated values that         //we want to see displayed in the view         return View('MyView', ViewData[someData]);      } 

I’m thinking that maybe the reason it’s not working is that I’m updating one form and then asking the MVC view engine to update/refresh the other form(but keep in mind that when I step thru the loop on the view that builds the page, the data is updated but the page in the browser is not)…How can I cause the view to display the correct html?

/********************************************
Added the following code just to test RedirectToAction
The ajax call DOES NOT error on the above return View(‘blah’) stuff
**********************************************/

P.S. Just tried RedirectToAction in the controller like this

 [AcceptVerbs(HttpVerbs.Post)]     public ActionResult Update(FormCollection frmUpdate)                 {         //go off and do some stuff...this part works as the ViewData          //is correct....meaning it has the updated values that         //we want to see displayed in the view         return RedirectToAction('MyView', new RouteValueDictionary( new { controller = 'Forecast', action = 'MyView', addMonth = monthAdd } ) );     } 

but then the ajax call errors with a 500 error

Thanks,
Greg

  • 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. 2026-05-11T14:36:17+00:00Added an answer on May 11, 2026 at 2:36 pm

    You’re almost there. This is how we do it.

    In the view, for the section that you want to update via ajax, copy the html from here to a partial view we’ll call Partial_View_of_Form and render it on the view. We’ll put this inside a unique div so we can replace this content later on…

    <div id='replace_me'>   <% Html.RenderPartial('Partial_View_of_Form', ViewData[someData]); %> </div> 

    For the Update() instead of returning a View, return the partial view we just created with the new values:

    [AcceptVerbs(HttpVerbs.Post)] public ActionResult Update(FormCollection frmUpdate) {     // do whatever processing you need here     return PartialView('Partial_View_of_Form', ViewData[updatedData])); } 

    Finally, in the ajax post, grab the html that you’re returning from the action and replace the contents of the original partial view.

    success: function(html) {     $('#replace_me').html(html);  } 

    This is pretty rough code and untested, but should be pretty easy to go from here

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

Sidebar

Related Questions

I want to perform some empirical trade-off's to assess the performance of applications written
What do I want to achieve: I want to perform some time consuming operations
I have a table on which I want to perform some operations every hour.
I want to create a simple batch file that would perform some Visual Studio
I want to perform cascade delete for some tables in my database, but I'm
I'm writing a class which will be used to perform some calculations on a
I have some values: $data1 $data2 $data3 I want to concatenate these variables and
I am developing an application that uses javascript to perform some arithmetical calculations in
I have Windows Form.Now i want to perform some function when the form get
I am using hibernate as ORM tool, i want to perform some common stuff

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.