Both dissolve in a similar way, but are different in the detail. They dissolve because they are able to form more stable bonds or associations with the solvent molecules than they have holding the solid together.
If we consider ionic solids first, then what is holding them together is the electrostatic attraction between the ions. When they dissolve, the ions form bonds with the solvent molecules, and the energy released when this occurs is more than the energy needed to overcome the electrostatic attractions in the ionic lattice. I have omitted talking about entropy here which also has a role - depends how much depth you want to go into...
For molecular solids, the force we must overcome is the intemolecular forces between the molecules. When dissolved, there will be intermolecular forces between the molecules of solute and the molecules of solvent. If these are stronger than those between the solute molecules when it is solid, dissolving will take place. Again entropy has a role to play and I have neglected it for simplicity.
There are a lot more differences than similarities between ionic and molecular compounds, but let's start with the similarities.
Both have a non-metal in them and both compounds are formed by the atoms trying to achieve a state of 8 (or 2) electrons in their valence (outer) shell.
The differences are numerous and basically define the two branches of chemistry, inorganic and organic. Ionic compounds are inorganic. They are formed by combining metals (+ ions) with nonmetals (- ions).
They are soluble in water (polar), conduct electricity in solution, and have high melting (freezing) and boiling points. Organic compounds are molecular also called covalent. They are formed by nonmetals sharing their outer shell electrons. Most are not soluble in water. Even if they dissolve they do not conduct electricity. They have low melting and boiling points. In fact most are liquids and gases at room temperature.