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

在NancyFx Razor中,如何在动作中获取渲染视图的html?,razor,nancy,Razor,Nancy,我有这样的案例:但我用的是NancyFx 有人知道怎么做吗?我想,我发现answare: 在 在该方法中,html位于“var content”中 附录:使用NancyFx将视图渲染为字符串的扩展 ViewLocationContext viewLocationContext = new ViewLocationContext() { Context = module.Context, ModuleName = module.Ge

我有这样的案例:但我用的是NancyFx


有人知道怎么做吗?

我想,我发现answare:

在该方法中,html位于“var content”中

附录:使用NancyFx将视图渲染为字符串的扩展
 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();
            }
        };