
48 Cal.Rptr.3d 871 (2006)
143 Cal.App.4th 326
Luis CANO, Plaintiff and Respondent,
v.
Ronald GLOVER, Defendant and Appellant.
No. B187267.
Court of Appeal of California, Second District, Division Six.
September 25, 2006.
*872 Marc A. Frost and Erich F. Fock, Myer & Fock, Santa Barbara, for Appellant.
Gregory J. Ramirez, Wasserman, Comden & Casselman, Oxnard, for Respondent.
YEGAN, J.
Ronald Glover (defendant) appeals from an order denying his motion for dismissal with prejudice. (Code Civ. Proc., § 581d; § 581, subd. (f)(2).)[1] He brought the motion after a demurrer was sustained and Luis Cano (plaintiff) did not name him in the fourth amended complaint. The trial court dismissed the action as to defendant, but without prejudice. The court also denied his motion for costs and attorney's fees on the ground that the motions were "premature." We reverse.

Procedural History
On July 25, 2004, plaintiff sued William Tucker and defendant for breach of contract, common counts, and fraud after investing in L & H Concrete, Inc. Plaintiff claimed that Tucker and defendant breached a June 2001 contract to share profits.
As to plaintiff's first, second and third amended complaints on the contract and common counts causes of action, the trial court sustained demurrers with leave to amend. Defendant's demurrer to a cause of action for breach of fiduciary duty was also sustained with leave to amend.
Plaintiff filed a fourth amended complaint but did not name defendant. Defendant moved for dismissal and requested costs and attorney fees. (§ 581, subd. (f)(2).) Plaintiff filed opposition to the motion *873 for costs and fees, but not the motion to dismiss.
The trial court stated that it was "dismiss[ing] Mr. Glover without prejudice. In terms of the breach of contract and common count, I think its premature to dismiss them at this point." The trial court was concerned that "something could turn up in discovery. He [defendant] has a responsible role in this. If I do it without prejudice, at least it gives [plaintiff] the option of including him."

Dismissal With or Without Prejudice
Section 581, subdivision (f) provides: "The court may dismiss the complaint as to that defendant, when:. . .[¶] . . . . . [¶] (2) . . . . after a demurrer to the complaint is sustained with leave to amend, the plaintiff fails to amend within the time allowed by the court and either party moves for dismissal." (Emphasis added.)
The phrase "may dismiss" means discretionary dismissal. (Weil & Brown, Cal. Practice Guide (Rutter 2005) Civil Procedure Before Trial, ¶ 11:277.2, p. 11-84.) But, no cases have held that a dismissal pursuant to section 581, subdivision (f)(2) may be without prejudice. The right to dismiss without prejudice is expressly permitted by other subdivisions of section 581 but section 581(f)(2) does not so provide. (See e.g., Wells v. Marina City Properties, Inc. (1981) 29 Cal.3d 781, 788-790, 176 Cal.Rptr. 104, 632 P.2d 217; Harris v. Billings (1993) 16 Cal.App.4th 1396, 1402-1403, 20 Cal.Rptr.2d 718.) "[A] plaintiff's right to a voluntary dismissal is cut off as of the moment there is a ruling which effectively disposes of the case." (M & R Properties v. Thomson (1992) 11 Cal. App.4th 899, 903, 14 Cal.Rptr.2d 579.) The dismissal without prejudice is also at variance with the California Rules of Court. Rule 325(f) provides for dismissal, by ex pare application or noticed motion, of "the entire action and for entry of judgment after the expiration of the time to amend following the sustaining a demurrer. . . ." (Emphasis added; see Datig v. Dove Books, Inc. (1999) 73 Cal.App.4th 964, 977, fn. 11, 87 Cal.Rptr.2d 719 [ex parte application must satisfy notice requirements of Cal. Rules of Court, rule 379].) Judgment may only be entered if the case has been adjudicated to finality.
Section 581, subdivision (f)(2) ". . . gives the defendant the right to obtain a court order dismissing the action with prejudice once the court sustains a demurrer with leave to amend and the plaintiff has not amended within the time given." (Parsons v. Umansky (1994) 28 Cal.App.4th 867, 870, 34 Cal.Rptr.2d 144, citing Wells v. Marina City Properties, Inc., supra, 29 Cal.3d at p. 789, 176 Cal.Rptr. 104, 632 P.2d 217.)
Plaintiff argues that a dismissal without prejudice is proper because defendant could still be brought into the case on a theory not tested by demurrer. We disagree. Plaintiff "was unable to amend the allegations of his complaint to satisfy the court that a cause of action was stated. He was given several opportunities to do so. To accept his present argument, . . . would allow him to reassert the same allegations in still another complaint, seeking a more favorable ruling from another court, rather than to proceed in a more appropriate, expeditious and final, course to appeal on the legal sufficiency of those allegations. [¶] The obvious consequence of such a statutory construction would be to prolong, rather than to terminate, lawsuits. It would not serve the orderly and timely disposition of civil litigation. No good reason appears why encouragement should be given to such tactics, the effect of which is to expose defendants to duplicative 'annoying and continuous litigation,' to burden our trial court with `fruitless' proceedings, and to delay the ultimate resolution *874 of the validity of the plaintiff's pleading. [Citation.]" (Wells v. Marina City Properties, Inc., supra, 29 Cal.3d 781 at pp. 788-789, 176 Cal.Rptr. 104, 632 P.2d 217.)
Here the dismissal without prejudice puts defendant in perpetual limbo, even on the issue of costs and attorney fees. Plaintiff forfeited his right to dismiss without prejudice when he filed the fourth amended complaint and did not name defendant. (6 Witkin, Cal. Procedure, Proceedings Without Trial (4th ed.1997) § 265, p. 683; Parsons v. Umansky, supra, 28 Cal.App.4th at p. 870, 34 Cal.Rptr.2d 144.) The failure to amend and state a cause of action against defendant is an admission that plaintiff has stated the case as strongly as he can and there are no facts that could be alleged to cure the defect. (Reynolds v. Bement (2005) 36 Cal.4th 1075, 1091, 32 Cal.Rptr.3d 483, 116 P.3d 1162.) "Somewhere along the line, litigation must cease." (In re Marriage of Crook, (1992) 2 Cal.App.4th 1606, 1613, 3 Cal.Rptr.2d 905 (conc. opn. of Yegan, J.).) After four unsuccessful attempts to state a cause of action against him, defendant should have repose.

Costs
The trial court denied costs on the ground that defendant's motion for costs was premature. It erred as a matter of law. "A defendant in whose favor a dismissal is entered is the prevailing party and is entitled to costs. (C.C.P. 1032(a)(4).) This is true where the plaintiff voluntarily dismisses or where the trial court orders an involuntary dismissal. [Citations]." (7 Witkin, Cal. Procedure (4th ed. 1997) Judgment, § 92, p. 623.) Defendant is entitled to costs regardless of whether the dismissal is with or without prejudice. (§ 1032, subd. (a)(4), see e.g., Catello v. I.T.T. General Controls (1984) 152 Cal.App.3d 1009, 1012, fn. 4, 200 Cal. Rptr. 4.)

Attorney Fees
The trial court denied attorney fees on the ground that "I am not convinced that a contract has been proven." There is no requirement that defendant prove the existence of a contract in order to recover attorney fees. Plaintiff is estopped by his pleadings which allege a contract based on a "Right of First Refusal Agreement."[2]
An attorney fee provision in both written and oral contracts may be enforced pursuant to Civil Code section 1717. (See A & M Produce Co. v. FMC Corp. (1982) 135 Cal.App.3d 473, 495, 186 Cal.Rptr. 114; cf. Khajavi v. Feather River Anesthesia Medical Group (2000) 84 Cal.App.4th 32, 62, 100 Cal.Rptr.2d 627.) "[A] prevailing defendant sued for breach of contract containing an attorney's fees provision and having had to defend the contract cause of action is entitled to recover its own attorney's fees and costs therefore, even though the trial court finds no contract existed." (Jones v. Drain (1983) 149 Cal.App.3d 484, 490, 196 Cal.Rptr. 827.)
Defendant prevailed at the pleading stage and is entitled to attorney fees. (Id., at p. at p. 489, 196 Cal.Rptr. 827.) "[I]t is extraordinarily inequitable to deny a party who successfully defends an action on a contract, which claims attorney's fees, the right to recover its attorney's fees and *875 costs simply because the party initiating the case has filed a frivolous lawsuit." (Id., at pp. 489-490, 196 Cal.Rptr. 827; see also Reynolds Metals Co. v. Alperson (1979) 25 Cal.3d 124, 128-129, 158 Cal. Rptr. 1, 599 P.2d 83, and Manier v. Anaheim Business Center Co. (1984) 161 Cal. App.3d 503, 508, 207 Cal.Rptr. 508.)
The judgment (order) denying defendant's motion for dismissal with prejudice and order denying attorney fees and costs are reversed. The matter is remanded with directions to enter a dismissal with prejudice in favor of defendant and to determine defendant's costs and attorney fees. Defendant is awarded costs and attorney fees on appeal in an amount to be determined in the trial court on noticed motion.
GILBERT, P.J., and COFFEE, J., concur.
NOTES
[1]  All statutory references are to the Code of Civil Procedure. An involuntary dismissal effected by a minute order signed by the trial court is an appealable order. (§ 581d; Topa Ins. Co. v. Fireman's Fund Ins. Companies (1995) 39 Cal.App.4th 1331, 1336, 46 Cal. Rptr.2d 516.)
[2]  The "Right of First Refusal Agreement" is attached to plaintiff's first amended complaint. Paragraph 19 of the agreement states: "Attorney Fees. In the event that any dispute among the parties hereto should result in litigation or arbitration, the prevailing party in such dispute shall be entitled to recover from the other party all reasonable fees, costs and expenses of enforcing any right of the prevailing party, including without limitation, reasonable attorneys' fees and expenses."

The second amended complaint prays for attorney fees, based on an oral contract, as does the third amended complaint.
