How to pray by the gravesite:
At the grave of a Tzaddik one is to pray to Hashem to answer his prayers in the merit of the Tzaddikim. Likewise one may ask the Tzaddik to intervene on one’s behalf and pray to G-d for the matters which he needs. Some are accustomed to recite the following prayer near the grave “May it be G-d’s will that the resting place of this person be with honor and his merit will stand on my behalf”. It is customary to recite a compilation of Psalm’s and prayers assembled in the booklet entitled “Maanah Lashon” upon visiting a gravesite of a Tzaddik. It is likewise customary to write a Pan and read it by the Ohel, [tearing it upon concluding its reading and placing it near the burial site.] [It is best to read the Pan towards the area of the Tzaddiks holy feet. If there are two Tzaddikim buried then it is to be read in between the graves by the feet.]
 Machatzis Hashekel 581/16; Drashos Mahril; Elya Raba 581/39; M”B 581/27
Other Opinions: The Ritva writes that one is not to Daven inside a cemetery due to the prohibition of Loeg Larash and rather he is to Daven outside the cemetery. [Machazik Bracha 581/7; Kaf Hachaim 581/91]
 Peri Megadim 581/16 based on the prayers found in the Maana Lashon; Kaf Hachaim 581/95 and 98 based on Shlah; Minchas Elazar 1/68 [brings many proofs from Midrashim; Talmud; Zohar]; Alef Lamagen 581/113; Minchas Yitzchak 8/53; Piskeiy Teshuvos 581/21; See Mahrahm Shick 293 for a list of opinions on this matter.
Other Opinions: Some Poskim are of the opinion that it is forbidden to ask the Tzaddik to intervene on ones behalf due to Doresh El Hameisim and one may only pray to Hashem in the merit of the Tzaddik. [See Drashos Mahril; Elya Raba 581/39; Levush 579; Machatzis Hashekel 581/16; M”E 581/50; M”B 581/27; Kitzur SHU”A 128/13 which writes one is not to place his focus on the Tzaddik.]
Why is asking the Tzaddik to intervene not forbidden due to paying to a foreign entity?
 Kaf Hachaim 581/92; Alef Hamagen 581/110
 Sefer Haminhagim p. 117 [English]
 Oatzar Minhagei Chabad 48
 Hiskashrus 884 based on Reshimos of Rebbe Rayatz regarding the custom of his father in Lubavitch