Two 12v batteries in series will do the trick.
You cannot operate a solenoid, relay, contactor, etc. marked for "DC" with an AC voltage. AC devices of these kinds have laminated cores while the DC versions do not. The DC coil will have eddy currents all over the place, heat up and use excessive current when operated on AC. In addition, without a shading coil that the AC versions would have, the solenoid could very likely chatter during use.
If you don't want to use batteries, you could use a DC power supply, such as the +12 v output of an old computer supply. Just remember that the pull-in current of a solenoid is momentarily higher than the holding current, just like starting current of a motor is higher than the running current.
Dean