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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:26:07+00:00 2026-06-01T07:26:07+00:00

A few days ago I asked this question about jquery ajax function invoking action

  • 0

A few days ago I asked this question about jquery ajax function invoking action in ASP.NET MVC controller. It’s now working the way it’s supposed to but I encountered another problem and I’ve been trying to solve it since then.

Scenario is that the player is creating a new character and is given free points to modify the character stats (strenght, agility and intelligence). I’m using view model to pass data from controller to view and TempData[“model”] for passing model between controller actions. Everything looks ok on server side. On click, ajax POST request is sent to server invoking ChangeStat method, character stats are modified in the model. Then I redirect to action which renders the View.

My problem is that the data displayed in the View are still the same (i.e. not updated according to modified model). I’ve read that it’s due to MVC validation and so HTML helpers first chceck for old value to display when rendering the same view. I suppose that it’s quite a common problem but I wasn’t able to find a solution. I’ve tried using ViewData instead of model, partial view with model/with ViewData but with no result. Below are code snippets. Hope we can find a solution or maybe my approach is wrong and there is better practice to solve this.

Controller action for changing stats:

[HttpPost]
public ActionResult ChangeStat(LobbyModels.StatChange stat) 
{
    int changeCoef = 0;
    LobbyModels.CreateCharModel model = (LobbyModels.CreateCharModel)TempData["model"];

    if (model.CharFreePts == 0)
    {
        return RedirectToAction("Create");
    }

    switch (stat.ActionName)
    { 
        case "Inc":
            changeCoef = 1;
            break;
        case "Dec":
            changeCoef = -1;
            break;
    }

    switch (stat.StatName)
    { 
        case "Str":
            model.CharStr = model.CharStr + changeCoef;
            break;
        case "Agi":
            model.CharAgi = model.CharAgi + changeCoef;
            break;
        case "Int":
            model.CharInt = model.CharInt + changeCoef;
            break;
    }

    model.CharFreePts = model.CharFreePts + (changeCoef * (-1));
    TempData["model"] = model;

    return RedirectToAction("Create");
}

Create method which renders the view:

public ActionResult Create()
{
    LobbyModels.CreateCharModel model = LobbyModels.CreateCharModel)TempData["model"];
    if (model == null)
    {
        // null model handling
    }

    TempData["model"] = model;
    return View(model);
}

and in View I render data from model with html helpers

<div id="CharStats">
    <%= Html.TextBoxFor(m => m.CharStr)%>
    <input type="button" id="Str_Inc" value="+" />
    <input type="button" id="Str_Dec" value="-" />
    <%= Html.TextBoxFor(m => m.CharAgi)%>
    <input type="button" id="Agi_Inc" value="+" />
    <input type="button" id="Agi_Dec" value="-" />
    <%= Html.TextBoxFor(m => m.CharInt)%>
    <input type="button" id="Int_Inc" value="+" />
    <input type="button" id="Int_Dec" value="-" />
    <br />
    <%= Html.TextBoxFor(m => m.CharFreePts)%>
</div>

ChangeStat function is missing some logic but that’s not a problem for now. My point is that I need to update textbox value according to current model data (or maybe try different approach completely).

  • 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-01T07:26:08+00:00Added an answer on June 1, 2026 at 7:26 am

    I am agreeing with @BigMike, you should be handing a JsonResult back to the View. Also, for best practice you should validate entries before the call to the action, that way you aren’t sending an ajax request if you don’t have to. So if you are validating before the ajax POST, then you can render the UI change before the ajax POST and use a void action for updating the data on the server.

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

Sidebar

Related Questions

few days ago i read tutorial about GenericRepository and Unit Of Work patterns http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application
I asked a question a few days ago about how to customise the calendar
A few days ago I has asked a question on SO about helping me
A few days ago i asked this question: Displaying images from Facebook photo albums
I asked a pretty similar question a few days ago, but this one is
A few days ago I asked a question about returning select fields from a
Few days ago I have asked a question about 1,2 and 3. degree connections.
A few days ago I asked a very similar question. I was about returning
I originally asked this question on the Highcharts forum a few days ago but
A few days ago I posted this question: switch statement and loops using jquery/javascript

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.