Query to SQL database in text saved by Tinymce

Asked

Viewed 97 times

2

I am using Tinymce to edit texts on my website. When I search a word with accent. Ex.: análise, query does not find why the database is saved in HTML an&aacutelise. I am using ASP.Net MVC with SQL Server.

  • And where’s your code and the relevant data to help you? Already I say that either you must change the way to save the data or you will have to change the searched terms to reflect the way it is saved.

  • Sorry, just follow the code. listaNoticia = context.GBV_Noticia.Where(x => x.idPessoa == idPessoa && x.dsConteudo.Contains(texto) && x.icAtivo == "S" && x.dtExclusao == null && x.dtPublicacao <= DateTime.Now && (x.dtForaDoAr == null || x.dtForaDoAr >= DateTime.Now)). Orderby(x =>x.dtPublication). Tolist();

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

1 answer

2

There’s not much information but basically what you need to do is treat HTML as a special way. You should decide whether to convert HTML to common text before saving it to the database or convert your search term to HTML encoding. You need to decide if you want to write as HTML itself or if the recording is in formed unsuitable for you and need to leave it in normal text.

Depending on what you need it won’t solve everything but this is the basic thing you should do.

Utility methods to do this: WebUtility.HtmlEncode() and WebUtility.HtmlDecode().

Following your code, it must be something like this:

listaNoticia = context.GBV_Noticia.Where(x => x.idPessoa == idPessoa &&
    x.dsConteudo.Contains(WebUtility.HtmlEncode(texto)) && x.icAtivo == "S" &&
    x.dtExclusao == null && x.dtPublicacao <= DateTime.Now &&
    (x.dtForaDoAr == null || x.dtForaDoAr >= DateTime.Now))
    .OrderBy(x =>x.dtPublicacao).ToList();

I put in the Github for future reference.

  • 1

    I did not test your code, but it seems to me that it would work as well. I solved otherwise, I added another parameter in the Tinymce script code. entity_encoding: "raw" Worked.

Browser other questions tagged

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