When young onion plants wilt for no apparent reason, pull up a sample plant to check for legless worms (maggots) feeding on it roots. Frequently the plant will break off as you pull it from the ground.
Floating row covers (fleece) are an effective way to prevent egg laying by adults. Be sure to get covers installed early, before the newly emerged adults fly in search of host plants. At the end of each season, be sure to pull all onions from the garden. Dig and move perennial onions every fall.
Remove badly damaged plants, as the maggots can move from one plant to another. Beneficial nematodes are the only effective treatment for this pest.
Yellow sticky traps or yellow pans of water can be used to monitor and trap onion flies.