سؤال

I am currently making a website that returns quite a few xml types and some of them are quite big. I don't really need to resort to xml serialization because it would be a bit slow in my case and some class fields must be only partially serialized depending on the context. I am using asp .net mvc 3.0 and .net.

So I imagined it would be great if I could use a technology similar to a view engine to generate those xml files. Maybe I could even use the existent razor view engine for this but I haven't seen anything remotely similar.

My question is if something like this exists or if I can use the existing technology to generate xml files in such a manner.

هل كانت مفيدة؟

المحلول

You don't need a technology "similar to Razor"... you can just use Razor ;)

You just need to specify the content type in the Razor view (and remove the Layout if necessary):

@using MvcApplication1.Models;
@model IEnumerable<Product>
@{
    Layout = "";
    Response.ContentType = "text/xml";
}
<?xml version="1.0" ?>
<products>
    @foreach (Product p in Model)
    {
        <product id="@p.Id">
            <name>@p.Name</name>
        </product>
    }
</products>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top