2012-01-05 5 views
17

나는 (아래 코드) 암시 적으로 내가 형 htmlstring의 변수에 값을 할당 할 때, 값이 XML 파일에서 읽고있는 'System.Web.HtmlString'에 유형 '문자열을'변환 할 수 없습니다 오류 "를 얻을C#에서 'string'유형을 'System.Web.HtmlString'형식으로 암시 적으로 변환 할 수 없습니까?

변환 방법은이 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 
}); 
+0

당신을 문자열을 갖는다. ['HtmlString'] (http://msdn.microsoft.com/en-us/library/system.web.htmlstring.aspx)를 원하십니까. 어떻게 다른 곳으로 갈 수 있습니까? 그리고 어떤 이슈가있을 수 있습니까? (힌트 : 다시 인코딩 할 수는 없지만 ...) –

답변

33

당신이 할 수없는 content =new HtmlString(c.Value); ?

+0

정말 빠른 오류를 수정 해 준 Sachin에게 감사드립니다! – Jarnal

+0

http://forums.asp.net/p/1755956/4765315.aspx/1?Help+Cannot+implicitly+convert+type+string+to+System+Web+HtmlString+ – Nope

관련 문제