Assignation of string with accents to another string, replaces them with "ó"

StackOverflow https://stackoverflow.com/questions/19409369

  •  30-06-2022
  •  | 
  •  

سؤال

I have a list of elements, and one of those elements field is a string value that contains an spanish-accented text which I see ok in the list. Once I enter de Detail page for one of those elements, the accents are shown like this ó

I have a string variable that contains the original Spanish-Accented text, and I assign that value to the new view. Example:

string a = "facturación";

view.Document = a;

and the field a of the class view is declared like this:

string Document { get; set; }

when I do a quickwatch over "a" I see "facturación".

when I do a quickwatch over "view.Document" y see "facturación"

what can I do?

Thanks in advance!

هل كانت مفيدة؟

المحلول

Found the error! The property was re-defined like this:

public string Document
  {
    get
    {
      return HttpUtility.HtmlEncode(txtDocument.Text);
    }
    set
    {
      txtDocument.Text = HttpUtility.HtmlEncode(value);
    }
  }

So the HtmlEncoding was the thing that was messing up with my string.

Thanks anyway!

نصائح أخرى

The reason this happens is that the view is escaping the string before rendering it. Use <%= Server.HtmlDecode(mystring) %> in your view to render the string un-escaped.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top