【问题标题】:In NancyFx Razor, how do I get the html of a rendered view inside an action?在 NancyFx Razor 中,如何在动作中获取渲染视图的 html?
【发布时间】:2014-11-08 22:20:20
【问题描述】:

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

谁知道,怎么做?

【问题讨论】:

标签: razor nancy


【解决方案1】:

我想,我找到了答案:

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();
            }
        };

【讨论】:

    猜你喜欢
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-21
    相关资源
    最近更新 更多