A search for the $C!P$-violating strong decays $eta to pi^+pi^-$ and $eta^prime(958) to pi^+pi^-$ has been performed using approximately $2.5 times 10^{7}$ events of each of the decays $D^+ to pi^+pi^+pi^-$ and $D_s^+ to pi^+pi^+pi^-$, recorded by the LHCb experiment. The data set corresponds to an integrated luminosity of 3.0 fb$^{-1}$ of $pp$ collision data recorded during LHC Run 1 and 0.3 fb$^{-1}$ recorded in Run 2. No evidence is seen for $D^+_{(s)} to pi^+ eta^{(prime)}$ with $eta^{(prime)} to pi^+pi^-$, and upper limits at 90% confidence level are set on the branching fractions, $mathcal{B}(eta to pi^+pi^-) < 1.6 times 10^{-5}$ and $mathcal{B}(eta^prime to pi^+pi^-) < 1.8 times 10^{-5}$. The limit for the $eta$ decay is comparable with the existing one, while that for the $eta^prime$ is a factor of three smaller than the previous limit.