Jon Archway
Jon Archway

Reputation: 4892

MVC Navigation Tabs

OK, I am now wondering how to handle navigation tabs with ASP.NET MVC. Giving an example, suppose you have the tabs like you have here at stackoverflow. So, Questions, Tags, Users, etc.

Now lets say you have a "sub tab" under this main one. So there were for example View and Add tabs displayed once you had selected the main Questions tab. Some questions:

public ActionResult Questions(string view)

public ActionResult Tags(string view)

Etc

Thanks in advance for any pointers

Upvotes: 1

Views: 1361

Answers (2)

tvanfosson
tvanfosson

Reputation: 532705

I think your controllers should be more closely bound to your model than your user interface (see my answer to this question). In general, I think you should think of a controller handling input for your model, i.e., do something to my model, then return a view (the UI) that corresponds to that action. The elements of your UI could, but do not necessarily have to, reflect the model hierarchy. For example, Questions, Unanswered, and Ask a Question in SO all seem to relate to the question model, but they are all top-level interface elements. Unanswered also seems to have it's own controller, but could easily have been implmented as .../questions/unanswered rather than as .../unanswered.

Upvotes: 1

Brian
Brian

Reputation: 4930

Your best bet would be to stick to REST. I would stick to having a controller per main tab and each sub-tab corresponding to the possible REST actions: index, new. Edit and delete are item-specific so wouldn't get tabs. Create is called by new and update by edit.

An exception to that in your example would be the 'Ask a Question' tab. Its at the same level as the Questions tab (index) but would call Questions/New.

Upvotes: 2

Related Questions