1

I want to create a razor XML view and render it. For exmaple:

@model SomeMessageClass

<?xml version="1.0"?>
<root>
    <message>
       <subject>@Model.Subject</subject>
       <to>@Model.To</to>
       <from>@Model.From</from>
       <body>@Model.Subject</body>
    </message>
</root>

How can I do this? Should I just use a cshtml file?

My end goal is to create an excel file dynamically using xml and razor. Then stream that file as a download to the user.

Lifes
  • 1,226
  • 2
  • 25
  • 45
  • you might want to consider this approach, http://stackoverflow.com/questions/134905/what-is-the-best-way-to-return-xml-from-a-controllers-action-in-asp-net-mvc it might work out better for you. – Kenneth Garza Apr 22 '13 at 23:17
  • I'm looking to do something similar to http://stackoverflow.com/questions/14741835/generating-dynamic-xml-in-razor?rq=1 – Lifes Apr 22 '13 at 23:21
  • You can user RazorGenerator http://haacked.com/archive/2011/08/01/text-templating-using-razor-the-easy-way.aspx/ – Evgeny Ivanov Jul 20 '16 at 15:27
  • Also you can use RazorEngine http://blog.micic.ch/net/generating-files-with-razor-engine – Evgeny Ivanov Jul 20 '16 at 15:39

0 Answers0