Force updating an element in HTML/Javascript/ASP.NET

Asked

Viewed 302 times

1

On the site I am working on, the user has access to a text editor to change the Labels in certain photos. When editing the text and giving "Submit" in the responses, the texts do not update on the pages - The same happened with the images of the site, but a solution was found, placing a random number at the end of all of them, maintaining the uniqueness.

The following photos demonstrate what I mean:

Imagem a ser atualizada

The image above has a label (Military Police, Navigators).

Below, the user has the possibility to change both the image and the text displayed next to it:

Foto 2, editor de texto

Values are not updated. The same was true of the images, but as stated, a random identifier was "pasted" in her name to the server (Azure) not to confuse.

What could be going on? (I am using cshtml/aspnet with mvc5!)

I’ve looked at several alternatives (both in English and in Portuguese) - most of them report meta tags that include "no-cache", "no-store", among others, but none seem to work.

  • Welcome to Stackoverflow in English. I edited your question to remove the greetings and thanks as we usually keep the text as clean as possible to focus on your scheduling question. If you are interested in visiting a part of the site that is not aimed to ask questions can know the [chat]. If you have questions about the operation, rules and procedures of the site visit the [meta] :)

2 answers

2


Hello,

Maybe it’s not the View, but the method you use to bring the contents of the database. If you are using EF to query in the BD, try to do it through a string query (e.g., "SELECT(fields) from dbo.Table") and run with Database.Sqlquery(QUERY). Tolist()

This causes the data to actually be brought from the database, forcing the update.

Att.

  • I improved my old solution with this. Obg!!!

1

In the signature of each Action that you do not want to cachear put the following annotation: [OutputCache(NoStore = true, Duration = 0)] in the following example I had problem with cache and solved in this way.

[OutputCache(NoStore = true, Duration = 0)]
public ActionResult LoginRegister()
{
}

Source(my own question, is a different purpose, but the solution is the same): How not to allow the user to access the previous login/registration page after logging in or registering

If not solve comments that we will find another solution.

  • Unfortunately these guarantees already are! I fear that the problem may be in the server get, since opening the page in private mode also does not recover the correct information. Thanks for the answer, Leo!

  • Where do you get the information from the images? via database?

  • @Momentanius ^^^

  • That’s it! I’m using SQL with Azure servers!

  • Are you sure the changes are being made in the bank?

  • @Momentanius, just type @pastedwith my name

  • Yes! With each update, I go to the database and refresh it. The data is sent there, but it is not being displayed correctly in the view. When I rebuild the entire project it gives updates, but before that, no.

  • There would be how you post the code you use to popular view?

  • controller code and view itself ?

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.