In NancyFx Razor, how do I get the html of a rende

2019-07-16 11:19发布

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?

标签: razor nancy
1条回答
姐就是有狂的资本
2楼-- · 2019-07-16 11:56

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();
            }
        };
查看更多
登录 后发表回答