Im trying the serialize the modelstate to an xml string. First I create a modelstate dictionary and this dictionary I try to serialize. This is the code I use:
ModelStateDictionary dict = new ModelStateDictionary();
dict.Merge(ModelState);
XmlSerializer serializer = new XmlSerializer(dict.GetType());
using (StringWriter writer = new StringWriter()){
serializer.Serialize(writer, dict);
var r2 = writer.ToString();
}
r2 is created, but all tags are filled with \r\n. What am I doing wrong?
You could use a XmlWriter and specify in the settings that you don’t want to keep whitespaces and indentation: