zchpit
zchpit

Reputation: 3121

In NancyFx Razor, how do I get the html of a rendered view inside an action?

I have case like: In MVC3 Razor, how do I get the html of a rendered view inside an action? but I'm using NancyFx.

Anybody known, how to do it?

Upvotes: 2

Views: 590

Answers (1)

zchpit
zchpit

Reputation: 3121

I think, I find answare:

in http://shanemitchell.ca/tag/nancyfx/

in that method, the html is in "var content".

 ViewLocationContext viewLocationContext = new ViewLocationContext()
        {
            Context = module.Context,
            ModuleName = module.GetType().Name,
            ModulePath = module.ModulePath
        };
        var rendered = module.ViewFactory.RenderView(viewName, model, viewLocationContext);
        var content = "";
        using (var ms = new MemoryStream())
        {
            rendered.Contents.Invoke(ms);
            ms.Seek(0, SeekOrigin.Begin);
            using (TextReader reader = new StreamReader(ms))
            {
                content = reader.ReadToEnd();
            }
        };

Upvotes: 1

Related Questions