Dynamically compose ASP MVC view based on context

Posted by robertFall on Stack Overflow See other posts from Stack Overflow or by robertFall
Published on 2011-01-02T18:49:24Z Indexed on 2011/01/02 18:54 UTC
Read the original article Hit count: 259

Filed under:
|
|

I have several views that are composed of several partial views based on context.

For example, we have a Project view that shows all the details of a project, which includes the scalar values, name etc, and also all the assigned employees, tasks and/or clients.

The problem I have is that certain types of project have all of the above sections while others have only two or even on section, ie. details only.

What is the best way to compose the Projects master view? I don't want to have logic to check the project in the view. Is there a way to compose a view in code by programatically rendering the relevant partials and ignoring the rest?

Otherwise are there any other ideas how to do this in a maintainable way? I could of course just render the partials using if statements to check if they apply, but that way the view contains VERY important logic. In another situation we want to use this method to display content based on the type of subscription a user has.

Thanks!

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about asp.net-mvc-2