用于显示数据的ASP.NET MVC的通用视图 [英] ASP.NET MVC generic view for displaying data

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

问题描述

我工作的一个项目涉及通过ASP.NET MVC应用程序暴露出许多数据实体(超过200)。
我不想写意见为每个实体模式,我想知道是否存在具有一个通用视图来显示不同​​的模式(例如,查看其内容的模特属性(元数据的方式),并生成一个HTML表格中显示实体的列表

I am working on a project involves exposing many data entities (more than 200) through an ASP.NET MVC application. I do not want to write views for every entity mode and I am wondering if there is a way of having one generic view to display different models (for example, a view which reads the model properties(metadata) and generates a HTML table to display a list of entities.

推荐答案

如果您只需要显示,你可以写在使用反射几分钟自己的通用渲染器。或者,你可以使用ModelVisualizer从MvcContrib或从电网 MvcContrib它可以做Html.Grid(型号).AutoGenerateColumns()来自动显示属性栏。它不支持DataAnnotations或属性,但你可以写,将使用反射的基础上的某些属性生成网格的行自己的扩展方法。您还可以使用的jqGrid的tableToGrid()方法,迅速将这一格变成jqGrid的。

If you only need to display, you can write your own generic renderer in few minutes using reflection. Or, you can use ModelVisualizer from MvcContrib, or Grid from MvcContrib which can do Html.Grid(Model).AutoGenerateColumns() to automatically show properties as columns. It doesn't support DataAnnotations or attributes, but you can write your own extension method that will use reflection to generate Grid's columns based on some attributes. And you can quickly turn this grid into jqGrid using jqGrid's tableToGrid() method.

如果您需要输入支持,还有就是几种选择:

If you need input support, there're several choices:


  1. MvcContrib的<一个href=\"http://www.lostechies.com/blogs/hex/archive/2009/06/17/opinionated-input-builders-part-8-the-auto-form.aspx\"相对=nofollow> InputBuilder (在这里你可以看到它是如何与反思做了一个简单的例子)

  2. MVC V2 InputFor(),我认为它支持渲染多个属性,但我不知道。

  3. 我的解决方案并读取元数据(属性)从视图模型,并自动生成的jqGrid格式和编辑选项。

  1. MvcContrib's InputBuilder (here you can see a simple example on how it's done with reflection)
  2. MVC v2 InputFor(), I think it supports rendering several properties, but I'm not sure.
  3. My solution does read metadata (attributes) from view models and generates jqGrid formatting and editing options automatically.

应该有商业工具了。

这篇关于用于显示数据的ASP.NET MVC的通用视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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