General view of ASP.NET MVC for displaying data

I am working on a project that includes many data objects (over 200) through an ASP.NET MVC application. I don’t want to write representations for each entity mode, and I wonder if there is a way to have one general view for displaying different models (for example, a view that reads model properties (metadata) and generates an HTML table to display a list of objects.

+1
source share
3 answers

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

If you need input support, there are several options:

  • MvcContrib InputBuilder (here you can see a simple example of how this is done with reflection)
  • MVC v2 InputFor(), , , .
  • () jqGrid.

.

+4

:

Asp.net Dynamic data, , ?

Asp.net MVC

, , , . ViewData. .

Routing
:

routes.MapRoute(
    "EntityRoute",
    "{entityName}",
    new {
        controller = "Entity",
        action = "Display",
        entityName = "SomeDefaultEntity" }
);

routes.MapRoute(
    "EntityRoute",
    "{entityName}/{recordId}",
    new {
        controller = "Entity",
        action = "Details",
        entityName = "SomeDefaultEntity",
        recordId = string.Empty }
);

, ViewData , . - ( , / ).

+2

MVC Contrib Model Visualizer, , . , - , , , .

0

All Articles