How to implement a StackOverflow profile page in ASP.NET MVC?

I'm guessing there is something in the StackOverflow code on the UserController lines that defines a function like this:

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

}

      

From what I can tell, there are two ways to implement the Profile function. One is to use a switch statement for the sort parameter and display a different view depending on what is being displayed (e.g. statistics, recent, replies). These views will then handle the partial user control to display the top half of the profile page (gravatar, username, last time, etc.).

Another way I could implement would be to always display one view and have logic to show / hide its different sections based on sorting. This will result in a rather monstrous browsing page, but it should work as well.

Are there other ways to implement the StackOverflow profile page that I am overlooking? The reason I am asking is because my current ASP.NET MVC page has a similar profile page, and I want to make sure I am not wrong.

0


source to share


2 answers


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



The url route scheme I would use is / {controller} / {id} / {section} eg / users / 123 / recent / users / 123 / replies etc.

+1


source


You can create view name from sort value

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

      



However, it defaults to the statistics view if the parameter doesn't exist, so I don't think they do that.

Switching to sort will probably work fine when, by default, the switch switches back to statistics view.

0


source







All Articles