When the mortgagee has commenced foreclosure proceedings, or the vendor demands or takes possession of the property covered by the contract, and it appears by the affidavit of the mortgagor or vendee, or the mortgagor's or vendee's agent or attorney, to the satisfaction of the judge of the district court of the county wherein such property is situated, that the mortgagor or vendee has a legal counterclaim or is entitled to take advantage of the provisions of section 28-29-07, or has any other valid defense against the collection of the whole or any part of the amount claimed to be due, such judge, by an order to that effect, may enjoin the mortgagee from foreclosing such mortgage by advertisement, or the vendor from taking possession of or selling such property, and may direct that all further proceedings be had in the district court having jurisdiction of the subject matter. For the purpose of carrying out the provisions of this section, service may be made on the mortgagee or vendor or the mortgagee's or vendor's attorney or agent. The provisions of this section apply to the assignee or transferee of any mortgagee or vendor and to the assignee or successor in interest of the mortgagor or vendee.
N.D.C.C. § 28-29-08