I am using asp.net web application with mvc3 . I am new to mvc3. I have a download button on my web page. when i click the download button i want to open this xml file .
I tried with some code changes in ActionResult , but I did not open the file. Using the code below, I get a download popup. when I am about to open the file, I get some kind of exception, as shown below. Can someone help me do this? Help solve this problem. :-)
Thanks at Advance.
My code in the controller:
public FileResult Download(string id) { string fid = Convert.ToString(id); var model = service.GetAllDefinitions().First(x => x.ID == id); var definitionDetails = new StatisticDefinitionModel(model); var definition = definitionDetails.ToXml; string fileName = definitionDetails.Name + ".xml"; string contentType = "text/xml"; return File(Encoding.Unicode.GetBytes(definition), contentType, fileName); }
The exception is:
The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. -------------------------------------------------------------------------------- A name was started with an invalid character. Error processing resource 'file:///C:/Users/asub/Downloads/fileNamegd... <
source share