Please note, I have an XML
file which contains such information to display into User. And I have got the XSL
file which contains the style information of the Content to display.
I wrote the following action in my controller to return the View which contains the XML
file contents.
public ActionResult GetError()
{
XmlDocument xdoc=GetXMLError();
return View(xdoc);
}
[#GetError.cshtml]
@model System.Xml.XmlDocument
@MvcHtmlString.Create(Model.InnerXml).ToHtmlString()
But the Screen renders the xml what it has retrieved as a String not a HTML String. Which means its printing the xml what I sent.
I have also included the XSL file in Corresponding View Folder.
I have no clue of further proceedings.
Could anyone help me to resolve this out to Render the XML in specified style format?
Finally I got the output. I thank @sundar G for his comment.
I changed the controllers as below,
public ActionResult GetError()
{
XmlDocument xdoc=GetXMLError();
XslCompiledTransform xsl = new XslCompiledTransform();
xsl.Load(@"D:\Development\Test.xsl");
XmlReader xReader = XmlReader.Create(new StringReader(xdoc.InnerXml));
StringBuilder stringBuilder=new StringBuilder();
XmlWriter xWriter=XmlWriter.Create(stringBuilder);
xsl.Transform(xReader, xWriter);
return View(stringBuilder);
}
And in the view.
@model System.Text.StringBuilder
@MvcHtmlString.Create(Model.ToString())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.