ASP.NET MVC查看后处理 [英] ASP.NET MVC View Post-Processing

查看:106
本文介绍了ASP.NET MVC查看后处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在单轨有一个转换过滤器的概念,其中渲染视图就可以申请将其进一步处理。用例:

In Monorail there's a transform filter concept, where a rendered view can then have further processing applied to it. Use cases:


  • 工艺降价

  • 删除空格

  • 带不想要的字符

我怀疑有没有外的即装即用的ASP.NET MVC这样做的方法,但没有任何人有一个建议的做法?我使用的是NVelocity视图引擎。

I suspect there is no out-of-the-box method of doing this in ASP.NET MVC but does anyone have a suggested approach? I'm using the NVelocity view engine.

推荐答案

我已经实现了一个可能的解决方案是创建一个自定义的ViewResult和做的工作在那里。这不是一个完美的解决方案,因为我基本上只是复制和粘贴正常执行到重写的ExecuteReuslt和调整渲染输出那里。该行:

A possible solution which I've implemented is to create a custom ViewResult and do the work in there. This is not an elegant solution, as I've basically just copied and pasted the normal implementation into the overridden ExecuteResult and tweaked the rendered output there. This line:

View.Render(viewContext, context.HttpContext.Response.Output);

变成了:

TextWriter writer = new StringWriter();

View.Render(viewContext, writer);

string renderedResult = writer.ToString();

renderedResult = renderedResult.Replace("hello", "goodbye");

context.HttpContext.Response.Output.Write(renderedResult);

相关来源是在这里:
HTTP://aspnet.$c$cplex.com/SourceControl/changeset /浏览/ 23011#288022

这是国际海事组织做的pretty可怕的方式,但它的作品。

This is a pretty horrible way of doing it IMO, but it works.

这篇关于ASP.NET MVC查看后处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆