I’m building an application using MVC3 that requires multiple sign ins. The first is standard forms authentication. Another is as a barrier to an administrative section and there is a third sign in for expired sessions.
I would like to reuse as much code as possible, but each page has some minor changes in them. For example, on the expired session, we want to change the username from an editable text box to simply displaying the username of the expired session. We would also want to change a little bit of text, like a title that says “Session Expired.”
What is the best practice?
Idea 1:
Should I re-use the view by adding some parameter strings and boolean flags to the controller which will set titles and whether things are editable? That would allow me to reuse controllers also.
Idea 2:
Have a separate controller/view for each. Since these pages are similar to eachother, but different from the rest of the application, I would create a new layout template and then have each view be separate.
Thanks ahead of time, you guys are awesome!
I think this is personal preference and how complicated you want to make your code.
Personally, and the way I’ve seen this happen the most, is have one view with some sort of editable flag set in the model that is passed to the view from the controller (however you present it via the view or partial).
HTH!