tags:

views:

487

answers:

1

I have a question about complex views in ASP.NET MVC. Where can I find good examples or best practice information on complex views and how best to create them in ASP.NET MVC. I know the basics, but peppering the HTML with complex dynamic HTML and/or jQuery seems to be messy.

Any links to enterprise best practices or examples from experience would be appreciated.

A: 

To reduce the complexity of pages I find myself developing ViewUserControls to encapsulate reusable functionality that gets included on multiple pages. Sometimes these are generic (like a GridControl), sometimes specific (like a set of role-based menu items that gets included only when the user is authorize). I use a master page to set up the basic outline of the page so it is common to all pages -- this includes the logon/logoff controls and menus. Each view, then includes the other ViewUserControls that it requires via the RenderPartial HtmlHelper extension.

The other thing that I've noticed is that I'm not trying to do as much per view as I would in a WebForms application -- actions and views are more smaller and simpler than many of my old WebForms pages. For example, I'll have a New and an Edit view, each of which includes a common ViewUserControl that contains the inputs for the form and a separate Show view that has no inputs, only spans with the contents. The actual views will be fairly simple and contain only the differences that you would notice between the forms. In a WebForm I would have had a templated DetailsView control and done it all in one form.

Since I'm working on my first MVC app -- it's an intranet app and not in production yet -- I can't really share a link. I'm still learning as I go, but this seems to be the natural direction for this application anyway. So far I haven't really found the markup to be more complex than the WebForm apps that I've developed.

tvanfosson