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

Volk Volk 551 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!

Developer technologies | ASP.NET | ASP.NET Core
Microsoft 365 and Office | Development | Office JavaScript API
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 1,510 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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.