当我尝试为 htmlstring 类型的变量赋值时,出现错误“无法将类型‘string’隐式转换为‘System.Web.HtmlString’,该值是从 xml 文件中读取的(下面的代码片段) )
convert 方法没有内置的从字符串到 htmlstring 的转换。有一种方法 ToHtmlString 但不确定在这种情况下如何使用它,因为它不适用于字符串对象。请提出您的建议。
public class Xclass
{
public HtmlString content { get; set; }
public string id { get; set; }
}
Xclass x = (from c in xdoc.Descendants("div") select new Xclass()
{
content = c.Value, //c.value is the html content of div, content is a property of type HtmlString
id = c.id
});
最佳答案
你能不能不做 content =new HtmlString(c.Value);
?
关于c# - 无法在 C# 中将类型 'string' 隐式转换为 'System.Web.HtmlString'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8738096/