0

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?

demongolem
  • 9,474
  • 36
  • 90
  • 105
Sravan
  • 1,095
  • 4
  • 16
  • 27
  • Please read this thread http://stackoverflow.com/questions/34093/how-to-apply-an-xslt-stylesheet-in-c-sharp – Sundar G May 21 '13 at 09:58

1 Answers1

0

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())
Sravan
  • 1,095
  • 4
  • 16
  • 27