This could only work for some effects.
Dispel Magic will only mitigate some Wild Magic Surge effects; specifically those that have a persistent effect on you personally. For example, dispel magic won't help against a fireball you cast on yourself. Fireball would need to be counterspelled, but contingency only works spells with a casting time of one action, and counterspell has a casting time of one reaction.
Another important thing to note about dispel magic is that it's indiscriminate:
Choose one creature, object, or magical effect within range. Any spell of 3rd level or lower on the target ends. For each spell of 4th level or higher on the target, make an ability check using your spellcasting ability. The DC equals 10 + the spell’s level. On a successful check, the spell ends.
A spellcaster doesn't get to pick and choose which effects get dispelled, so the contingent dispel magic will also affect any defensive or protective spells that are affecting them.
Further, while there are no limits in the PHB on the complexity of the condition that can be defined for contingency, the DM might not allow overly long or convoluted conditions. For example, in order to prevent abuse, they might require that a player whose character is casting contingency verbally express the triggering condition without recourse to notes. Or they might only allow simple conditions without any kind of logical conjunctions (and, or, if, etc).
In this particular case, the DM might rule that the player doesn't know all of the possible outcomes from a Wild Magic Surge, and so there's no way they can enumerate them all in order to protect themselves.
... "what if the condition instead was: if Wild Magic Surge affects me or my allies in a harmful or disadvantageous way, except a self-fireball?"
The DM might also limit the amount of decision-making that a contingency can perform. Conditions that include phrases like "in a harmful or disadvantageous way" might not be possible, or (worse) not be reliable; the contingency spell might (for example) decide that turning into a potted plant is advantageous under some circumstances.
Additionally, remember that contingency only casts the spell on the caster, not on any other targets. If you really want to cast dispel magic on yourself any time a Wild Magic Surge affects your allies, you can, but that's probably not what you want.