自定义视图引擎与自定义操作结果
我有一个场景,用户可以选择单击“下载”按钮,我应该创建一个包含历史数据的 csv 文件,然后让用户在本地保存该文件。由于我以前没有这样做过,所以我开始寻找如何执行此操作,并且基本上遇到了自定义视图引擎和自定义操作结果。
我现在的问题是这些的优点/缺点是什么?首选的方法是什么?
CSV 文件基本上只包含标题和数千行数据(最多约 15 列/字段)。所以真的没什么特别的。
I have a scenario where the user have the option to click the button "download" and I should create a csv file, that contains history data, and then let the user save the file locally. As I haven't done this before, I started to look around for how to do this and basically came across both Custom View Engine, and Custom Action Result.
My question now is what is the benefit/disadvantages with these? What is the preferred way to go?
The CSV file, is basically just containing headers, and data (up to about 15 columns/fields) with a few thousand rows. so nothing special really.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能会选择自定义操作结果(我的示例中的实际序列化是通过 FileHelpers 完成的):
您可以甚至通过使用扩展方法来美化这个 return 语句(在这种情况下泛型是丑陋且多余的):
然后简单地:
I would probably go for a custom action result (the actual serialization in my example is done with FileHelpers):
You could even prettify this return statement (generics are ugly and superfluous in this case) by using an extension method:
and then simply: