Using ASP.NET MVC with General Views

I am currently studying MVC for a new project that we are launching. While I like it, but I'm curious about something.

The actual views that we will display will not be known at design time, we will indicate somewhere in the configuration file how to create these views. Is this template supported by MVC or do we need to know during development exactly what data we will be viewing?

If not, can someone give me some pointers to what I should look at, as most of the information I assume you have a model / view that is defined during your design.

Hello,

Alex ..

+5
source share
2 answers

Your views may be poorly displayed ... Your initial directive on the page will look like this:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

... and then you can reference data from your controllers, for example:

<%= ViewData["MyData"] %>

Is there some kind of common interface that you are going to convey to your view? If so, you can take advantage of using the generic ViewPage <>:

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IamTheInterface>" %>

Then you can use your interface to reference your model:

<%= Model.MyProperty %>
+6
source

LosTechies.com has a cool post that describes how to create an “auto form” with fields that are auto-generated from the model’s properties. Look, this may be what you are looking for.

+3
source

All Articles