-1

Possible Duplicate:
Url routing with database lookup?

I am looking to build a CMS, This will mean that the user can add pages to the system, this will invlolve entering the URL and then the content as HTML in a Rich text editor.

How will MVC3 routing handle this? as I understand the Controller/Action method hits an action and returns a View() but if this URL Controller/Action exists in a database and points to content in a database

Basically I need the system to check if the route exists if not get the html from the database and display the View()

e.g. /Account/EditUser

In my controller I have

public ActionResult EditUser(){

    return View();
}

public ActionResult LoadCMS(String URL){
    // check URL exists in DB
    // get the html from db
    // return the Html as a View to the user
    // if not exists then return error page
}

But what do I do when I request a CMS page:

e.g. /Account/DisplayUser

in my controller there is no DisplayUser Action so go to LoadCMS Sorry I have no idea where to start on this so I have no code to give.

Any help or direction would be appreciated.

Thanks

Community
  • 1
  • 1
CR41G14
  • 5,464
  • 5
  • 43
  • 64

1 Answers1

0

in my controller there is no DisplayUser Action so go to LoadCMS Sorry I have no idea where to start on this so I have no code to give.

As I understand this you need to display User Information using the action DisplayUser. So you can create an action like the one below.

 public ActionResult DisplayUser(string username){
    var userDetails = GetDataFromDatabase(userId);
    return View("User", userDetails);
 }

So this action can now be reached using the url www.website.com/Users/DisplayUser/yrshaikh assuming this action is inside the UsersController Controller and yrshaikh is the username.

For more understanding you can try and understand the profile link each user has on stackoverflow, like for example mine is https://stackoverflow.com/users/1182982 here the userId is 1182982 and the controller name is users (this can be different if custom routing is done.)

So, I hope with this information you can get started...

Community
  • 1
  • 1
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281