在NancyFx Razor中,如何在动作中获取渲染视图的html?

时间:2014-09-15 11:38:32

标签: razor nancy

我的情况如下:In MVC3 Razor, how do I get the html of a rendered view inside an action?但我正在使用NancyFx。

有人知道,怎么做?

1 个答案:

答案 0 :(得分:1)

我想,我找到了answare:

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

中的

在该方法中,html位于" 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();
            }
        };