tags:

views:

124

answers:

2

I'm guessing the StackOverflow code has something along the lines of a UsersController that defines a function like this:

public ActionResult Profile(string id, string username, string sort)
{   

}

From what I can tell, there's two ways to go about implementing the Profile function. One is to use a switch statement on the sort parameter and render a different view based on what is being displayed (e.g. stats, recent, responses). These views would then render a partial user control to handle the display of the top half of the profile page (gravatar, username, last seen, etc).

The other way I could see implementing this would be to always render one view and have the logic for showing / hiding its different sections based on the sort. This would lead to a pretty monstrous view page, but it should work as well.

Are there any other ways of implementing the StackOverflow profile page that I'm missing? The reason I ask is because my current ASP.NET MVC page has a similar profile page and I want to make sure I'm not going about this the wrong way.

+1  A: 

Personally, I would create an action and view for each tab section and use a partial view for the top part that is shared across the others. I'm just getting started with MVC though, so I don't have a lot of experience to back up that suggestion.

The URL route scheme I would use is /{controller}/{id}/{section} e.g. /users/123/recent /users/123/responses, etc.

John Sheehan
A: 

You could build the view name from the sort value

<% RenderPartial(sort + "View") %>

However, it does default back to the stats view if the parameter doesn't exist so I don't think they are doing that.

A switch on sort would probably work just fine with the default on the switch going back to the stats view.

Todd Smith