我有一个带有c#代码的asp.net应用程序。尝试使用类序列化为xml。但是得到错误:
System.Web.UI.WebControls.Literal lit = new System.Web.UI.WebControls.Literal();
lit.Text = System.Web.Optimization.Scripts.Render("~/bundles/my_js").ToHtmlString();
Header.Controls.Add(lit);
此行发生在:
cannot implicitly convert Cannot convert type system.collection.generic.list
.CS文件代码:
CourtDocumentEvent = new List<DocumentEventCourtDocumentEvent>
答案 0 :(得分:0)
此代码将您的对象转换为XML
public static string ConvertToXml(object obj)
{
StringWriter result = new StringWriter(new StringBuilder());
try
{
XmlSerializer serializer = new XmlSerializer(obj.GetType());
serializer.Serialize(result, obj);
return result.ToString();
}
catch (Exception ex)
{
return result.ToString();
}
}