PWM that can handle rapid on and off cycles?
Conceptually, you want something like this: 







simulate this circuit &ndash; Schematic created using CircuitLab

When you turn M1 on, the current rises in the solenoid, charging the magnetic field up. When you turn it off, the current decreases towards zero, flowing through the diode or upper MOSFET. If you PWM fast enough relative to the inductance, the current will be fairly steady.  

There are suitable modules available for M1 (MOSFET) and D1 (Schottky diode). The diode can also be replaced by another MOSFET which may result in better efficiency. however shoot-through has to be avoided or there could be a spectacular failure. 

For example, this module.