I'm writing an helper that basically receives many RouteValueDictionary and returns many links; I'd like to skip links to the current route values (example: in /Products/Details/3 there should not be a link to /Products/Details/3), ignoring other URL params if any.
What I can think of is to check if:
destination action and controller name are null or equal to the current ones;
each other destination route value is defined and equal to the current ones and vice versa.
Is there a better way?
EDIT:
Some context: I have many models, many controllers, many actions. I don't like the idea of writing the same stuff over and over again everywhere, so I decided to code a general solution: permission aware icon links (I asked for hints here).
I now have a PermissionAwareIconAction class, which has an Icon, a HasPermission() method, a delegate to obtain the URL and few other stuff. Inside Global.asax.cs I call few methods to fill an ActionTable, that contains all this stuff, with code like this:
CrudAction.CreateCrudActions<Vendors>(Permissions.CreateVendors,
Permissions.EditVendors,
Permissions.DetailsVendors,
Permissions.DeleteVendors);
and, of course, code to add other specific actions.
I also decorate my controllers actions with:
[Action(typeof(Vendors), "Create")]
public ActionResult Create()
{
...
}
Inside views, I do:
<%= Html.IconActionLinks<Vendors>() %>
In views not related to a single object, like Index, and
<%= Html.IconActionLinks<Vendors>(Model) %>
In views related to objects, like Details.
This way, Permissions are defined in just one class; also, code to show or not to show a link to Edit based on permissions is the same code to allow or not allow user to see the Edit action.
I'm almost done (I plan to post a reply to my previous question, resuming what I've done, when I'm done).
Now I have still to do this little piece, avoid Details icon in Details view, Index icon in Index view and so on.
Forgive me for the long post.