-1

I am currently evaluating ASP.NET MVC as a possible technology for a web project. As I am a beginner to ASP.NET MVC I need a bit of advice.

We currently have an ASP.NET system that renders grids from data that is retrieved from a database using OLE DB and data tables. The data is rendered on a web page using a grid view that uses the columns from the database. The system is built in a generic way and driven from the database so that we do not have to write a custom page to display and render each table in the database. We effectively have one ASP.NET page that is used to render and edit different tables in the database.

We are looking at rewriting the system using ASP.NET MVC. Is it possible to have generic models, controllers and viewers in ASP.NET MVC that use dictionaries or lists instead of having separate classes for each table in a database? On the controller side I have seen the following article to convert a data table to an IEnumerable:

Convert DataTable to IEnumerable

However, I am not sure whether the same can be achieved on the model and viewer side. Is the whole idea of generic models, controllers and views perhaps contrary to the idea of ASP.NET MVC?

Regards Lucas

Community
  • 1
  • 1

2 Answers2

0

First, you don't need custom models for views or controllers if you know you will be using something generic.

Second, you can write editor/display templates that can work on generic data and you can use them in your views.

linkerro
  • 5,318
  • 3
  • 25
  • 29
0

We are looking at rewriting the system using ASP.NET MVC. Is it possible to have generic models, controllers and viewers in ASP.NET MVC that use dictionaries or lists instead of having separate classes for each table in a database

Generic solutions are very often a excellent recipe for maintenance nightmare. They work well until you have to extend the application. In my experience you do not switch from the generic solution when you want something extra, but do a small workaround. Next time you'll add another small workaround. And after a year you do not want to touch that application again.

If that's not the case for you, congratulations! You can just use a DataTable as your model in the view.

jgauffin
  • 99,844
  • 45
  • 235
  • 372