5

I am currently investigating MVC for a new project we are starting. So far I like it, but I'm wondering about something.

The actual views that we will be displaying will not be known at design time, we will be specifying in a config file somewhere how to build these views. Is this pattern supported by MVC or do we need to know at design time exactly what data we will be viewing?

If not, can someone give me some pointers on what I should be looking at as most of the info I have assumes that you have a model/view that is defined during your design.

Regards,

Alex..

2 Answers 2

6

You can have your views weakly-typed... Your initial page directive on the view will look like:

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

... and then you can refer to data from your Controllers like this:

<%= ViewData["MyData"] %>

Is there some common interface that you are intending to pass to your view? If so, you can benefit from a using the generic ViewPage<> :

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

Then, you can use your interface to refer to your Model:

<%= Model.MyProperty %>
Sign up to request clarification or add additional context in comments.

1 Comment

Hi Jeff, This looks like good stuff thanks... Yes, each view will have exactly the same interface, basically just a grid with CRUD facilities.
3

There is cool post in LosTechies.com about building an "autoform" with fields autogenerated from the Model properties. Take a look, it might be what you are looking for.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.