
253 N.W.2d 915 (1977)
Earl RIEDIGER and Marvel Riediger, Appellants,
v.
MARRLAND DEVELOPMENT CORPORATION a/k/a Marrland Development Co., Inc., Appellee.
No. 2-58506.
Supreme Court of Iowa.
May 25, 1977.
*916 O'Brien & O'Brien, Sioux City, for appellants.
Crary, Huff, Yates & Clem, P. C., Sioux City, for appellee.
Submitted to MOORE, C. J., and LeGRAND, UHLENHOPP, REYNOLDSON and HARRIS, JJ.
LeGRAND, Justice.
This is an appeal from an order sustaining defendant's motion to dismiss plaintiffs' petition. We reverse.
On June 29, 1973, plaintiffs filed a petition asking that defendant be estopped from forfeiting their interest in a certain land contract, alleging the notice of forfeiture falsely stated they were then $6,000 in default under the contract terms. On July 18, 1973, defendant filed its answer, admitting the formal matters set out in the petition and reiterating the contract was in default. Issue was thus joined on the critical question concerning default in payment of $6,000.
On April 22, 1974, a certificate of readiness was filed. The case was thereafter twice continued by court order to avoid dismissal under Rule 215.1, Rules of Civil Procedure.
On April 25, 1975, defendant filed its motion under Rule 104(b), R.C.P., to dismiss plaintiffs' petition. Under our rules such a motion serves the same purpose as a demurrer formerly did. Bales v. Iowa State Highway Comm'n., 249 Iowa 57, 62, 86 N.W.2d 244, 247 (1957).
A motion to dismiss may be sustained only when the petition fails to state a cause of action upon which any relief could be granted. Like a demurrer, it must be filed before answer. In the present case answer had been filed and issue joined almost two years before the motion was filed.
In Newton v. City of Grundy Center, 246 Iowa 916, 920, 70 N.W.2d 162, 164 (1955), we said:
"Such motion [to dismiss] is now almost as unnecessary as the similar obsolete pleading of demurrer * * * Other available proceedings for disposition of matters on their pleadings after answer virtually eliminate the need or use of the motion to dismiss for failure to state a claim. * * *" (Emphasis added.)
In Brown v. Correll, 227 Iowa 659, 660-661, 288 N.W. 907, 908 (1940), a case arising under the old demurrer statute, defendant attempted to demur after he had filed answer without first securing permission to withdraw his answer. We said this was improper. But see Harrison v. Allied Mutual Casualty Company, 253 Iowa 728, 730, 113 N.W.2d 701, 702 (1962).
We hold the motion was not timely, and the order of dismissal was improvidently entered.
II. Even if we were to consider the disputed ruling on the merits, we would reach the same conclusion because the trial court went outside the pleadings in reaching its decision.
A motion to dismiss must stand or fall on the matter alleged in the petition. It can neither rely on facts not alleged (except those of which judicial notice may be taken) nor may it be aided by an evidentiary hearing. Stearns v. Stearns, 187 N.W.2d 733, 734 (Iowa 1971); Ke-Wash Company v. Stauffer Chemical Company, 177 N.W.2d 5, 9 (Iowa 1970); Herbst v. Treinen, 249 Iowa 695, 699, 88 N.W.2d 820, 823 (1958). It is true we entertained the Stearns appeal despite the improper procedure followed there, but only because the importance of settling the custody of children impelled us to do so. No such persuasive circumstance appears in the present case.
The trial court in the case now before us held an evidentiary hearing. Its ruling on the motion was virtually a decision on the merits. That is not the function of a motion to dismiss.
*917 We said as much in Harrison v. Allied Mutual Casualty Company, supra, 253 Iowa at 731, 113 N.W.2d at 702-703, where this appears:
"A motion to dismiss assumes the truth of facts well pleaded in the pleading attacked but is not a proper vehicle for the submission of affirmative defenses. The trial court, in an obvious and ordinarily commendable effort to reach an ultimate decision, went beyond the boundary of the limited problem involved [by considering facts not alleged in the petition.] While we approve of prompt disposition of ultimate issues, we cannot sanction disregard of proper methods in determining controverted facts."
That same observation is applicable here.
The order of dismissal is accordingly set aside and the case is remanded for further appropriate proceedings.
REVERSED AND REMANDED.
