views:

51

answers:

1

I'm developing an ASP.NET MVC application where the content for any page can be pulled from the database, if it exists, and displayed on the page.

This is to make it possible for non-technical persons to edit the content without having to go into the source code (e.g. views) and change things.

The way I'm doing this is, each controller derives from a base controller. The base controller overloads 'OnActionExecuted' and takes this opportunity to pull any content assigned to the current Action/Controller.

If the action returns a ViewModel that derives from 'ContentViewModel', it populates the 'Text' property of the ViewModel with the text from the database.

And then the text gets rendered by the View.

Can you see any weakness to this design?

Would it be better if, rather than having a base controller, I had HtmlHelper extensions for pulling content, which I call from the View?

One reason I'm asking this is, having my own base controller seems to interfere with calling 'Html.RenderAction', which seems to expect the specified controller to directly inherit from 'System.Web.Mvc.Controller'.

+1  A: 
  1. ActionFilters should not be used to pull the content.

  2. Controllers should not be used to pull the content but only to dispatch the incoming requests by applying simple logic.

  3. HTML helpers should not be used to pull any content. They are meant to render UI elements prefilled with the supplied data.

application where the content for any page can be pulled from the database

That's basically how most applications operate.

This is to make it possible for non-technical persons to edit the content without having to go into the source code (e.g. views) and change things.

For non-technical persons to edit content there should be an appropriate UI. Independently of the project underlying technology, non-technical personal is never supposed to edit the code.

I suggest you don't make anything weird but keep things clear. Implement your business layer that will supply the data to models which the view will render. Create a UI for other people to edit the content.

Developer Art