TempData['value'] and ViewBag.value are updated in the controller, but remain same in the view

Volk Volk 571 Reputation points
2023-11-22T12:44:34.68+00:00

Hi!

Using $.ajax, I update variables in TempData or in ViewBag without reloading the page (View).

But when the result of success: function (result) {} is returned in the View, the alert shows that the data has not changed.

As far as I understand, I definitely have to reload the page from the return View() controller? But I don't want to reload it.

Is there any way to change a variable in the View without reloading the page?

Thanks!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,360 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
931 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 1,495 Reputation points
    2023-11-22T13:48:12.4866667+00:00

    TempData and ViewBag are designed to pass data from the controller to the View. It is not possible to update TempData or ViewBag without making a trip to the server.

    Is there any way to change a variable in the View without reloading the page?

    I'm sure there is a way to solve the current programming problem if you explain the use case and share code that illustrates the issue.


0 additional answers

Sort by: Most helpful