Methyl acrylate connects covalently with alkylpyridinium bromide to build N-alkyl-3-(2-methoxycarbonyl-vinyl)pyridinium bromide (MPA-n, n=8–14). MPA-n inhibited X70 steel from corrosion in 5M HCl with inhibition efficiency of 98% and the inhibition capacity was in the order of MPA-14>MPA-12>MPA-10>MPA-8. Quantum chemical calculation unveiled that MPA-n adsorbed on iron surface by O atom in MA moiety offering electrons to d orbital of iron and by π* orbital of pyridinium accepting electrons from iron, and MPA-n with longer alkylchain possessed higher E HOMO , lower ΔE, larger molecular volume and dipole moment, all suggesting the same corrosion inhibition order as that in experiments.