views:

103

answers:

2

This may be more of a best practice question.

I have three views (create/details/edit) that all link to their own results view (createResults/detailsResults/editResults). Each results view shares a partial with a results table on it.

When a user submits one of the three (c/d/e) views, should each results view have its own action, even tho the action will quite literally do the exact same thing (search on the information on the c/d/e view)? I'd rather not duplicate this code if not necessary.

Should I have one action, and pass in something that tells the action which results view to direct to? Is there an easy way to get the referring view in the action?

A: 

I would make a single action with a string parameter containing the view name.

You can play with the routing table to make the URLs prettier.

SLaks
My only complaint about this is that it wouldn't be strongly typed.
Brett
+2  A: 

If you have 3 actions you don't need to duplicate code. Why not refactor the common code into a single private method on the controller, or perhaps even move it into an action filter?

richeym