Question

I'm working on a mini CMS-like application using asp.net MVC 1.0 (I will upgrade it once 2.0 is released). Once feature I want, that is pretty vital to a CMS, is the ability for an admin to add pages to their site.

Essentially, if the admin wants to add a page called "Links", I want them to be able to do so without having to go through any of the hassle of adding the action to the controller and compiling a new assembly.

I have an idea for a solution and I want to know what the community thinks.

I think that I should write a class called (for arguments sake let's call it UserGeneratedGenericController) that extends the Controller class. In this class, I will have a single Action that reads a parameter and redirects to the View that corresponds with the parameter passed to the action.

I will also have to edit the Routing in the Global.asax.cs file

therefore /UserGeneratedGenericController/Links will hit the same Action that /UserGeneratedGenericController/News will hit, but will display the views as desired.

What say you? I'm interested in your comments on this approach and your suggestions to other approaches.

Was it helpful?

Solution

i think what you presented is the way to go

OTHER TIPS

You want to take the page title, and create a unique url slug for it, then you want to be able to load the content from the database based on the url slug (using the url slug as the id, rather than an actual database id).

public ActionResult Index(string UrlSlug) {
  // Get Content For Page {UrlSlug}
}

So your route would be /Pages/{UrlSlug} and a sample would be /Pages/Links. Then your Index action on your PagesController would pull off the url slug (Links) and load the appropriate content from storage, and render the content inside your master layout. I think you were thinking along these lines, just make sure when the user adds a page, you create a unique url for it. Replace spaces with underscores, remove special characters, etc to create a url safe key to use to load the page information when it is requested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top