
176 Cal.App.3d 1191 (1986)
222 Cal. Rptr. 656
D & J, INC., Plaintiff and Respondent,
v.
FERRO CORPORATION, Defendant and Appellant.
Docket No. G001428.
Court of Appeals of California, Fourth District, Division Three.
January 28, 1986.
*1193 COUNSEL
Gibson, Dunn & Crutcher and Frederick R. Wirtz for Defendant and Appellant.
John W. Dumas for Plaintiff and Respondent.
OPINION
CROSBY, J.
Is a dismissal of an action at the request of the plaintiff after the commencement of trial "voluntary," thus precluding an award of attorneys fees under Civil Code section 1717? Yes.

I
(1) D & J, Inc. sued Ferro Corporation for breach of contract. During an in limine examination of the first witness, plaintiff moved to dismiss the action with prejudice. (Former Code Civ. Proc., § 581, subd. 5, now Code Civ. Proc., § 581, subd. (e).) The motion was granted, and defendant submitted a memorandum of costs and disbursements and sought to be declared the prevailing party in order to receive attorneys fees under Civil Code section 1717. Relying on subdivision (b)(2), the trial court determined there was no prevailing party. It provides, "Where an action has been voluntarily dismissed or dismissed pursuant to a settlement of the case, there shall be no prevailing party for purposes of this section."
Ferro claims the dismissal was not "voluntary" within the meaning of Civil Code section 1717 because it was entered after commencement of trial and was with prejudice. These factors, retort D & J, are of no consequence: Because the plaintiff initiated the request for dismissal, and because it was with prejudice, the court performed only a ministerial function in entering it. Thus, the dismissal must be viewed as voluntary. We agree.

II
(2) A defendant dismissed from an action is entitled to costs as a matter of right. (Code Civ. Proc., § 1032.) The rule applies whether the dismissal *1194 is voluntary or involuntary. (International Industries, Inc. v. Olen (1978) 21 Cal.3d 218 [145 Cal. Rptr. 691, 577 P.2d 1031].) (3a) As a general rule, a dismissal ordered by the court is considered to be involuntary while one entered at the request of a party is voluntary. Only the former requires a "written order signed by the court [which, when] filed in the action[,] ... shall constitute [a] judgment[]...." (Code Civ. Proc., § 581d.)
(4) Where a party is entitled to attorneys fees pursuant to Civil Code section 1717, they are recoverable as costs. (T.E.D. Bearing Co. v. Walter E. Heller & Co. (1974) 38 Cal. App.3d 59, 62, 64 [112 Cal. Rptr. 910].) However, in order to encourage settlements, the Supreme Court has determined that "sound public policy and recognized equitable considerations [preclude an award of attorneys fees as costs] when the plaintiff voluntarily dismisses prior to trial." (International Industries, Inc. v. Olen, supra, 21 Cal.3d at p. 223, italics added.)
Subdivision (b)(2), subsequently added to Civil Code section 1717, ensures that attorneys fees will not be awarded where an action has been voluntarily dismissed. (Stats. 1981, ch. 888, § 1, pp. 3399-3400.) Under that circumstance, the statute declares there is no "prevailing party" to whom an award of attorneys fees may be made. Subdivision (b)(2) does not require that the dismissal be entered before trial.
Ferro insists that any dismissal which is entered after the commencement of trial must be considered involuntary. But the parties have not cited, and we have not found, a case which has determined the point. (5) We will conclude, however, that a dismissal under former Code of Civil Procedure section 581, subdivision 5 is voluntary.
(3b) It is not the stage of the proceedings which distinguishes a voluntary dismissal from an involuntary one. Rather, the key is the plaintiff's role, if any, in bringing it about. For example, where the court grants a defense motion to dismiss or when the court dismisses a pleading on its own motion, without the consent of the plaintiff, the dismissal is obviously involuntary. (See former Code Civ. Proc., §§ 581, subds. 3, 6; 581a; and 583.) Dismissals in this category invariably require a written order signed by the judge. (Code Civ. Proc., § 581d.)
If, however, a complaint or even a single cause of action is dismissed at the request of the plaintiff or by stipulation of the parties, the dismissal is voluntary. (See former Code Civ. Proc., § 581, subds. 1, 4, and 5.) Dismissals of this type may be obtained without application to the court at all; a written request to the clerk will suffice. (Code Civ. Proc., § 581d.)
*1195 An analysis of dismissals under former Code of Civil Procedure section 581, subdivision 4 (now Code Civ. Proc., § 581, subd. (d)) is instructive. That subdivision provided for a dismissal "[b]y the court, with prejudice to the cause, when upon the trial and before the final submission of the case, the plaintiff abandons it." (6) Although a dismissal under subdivision 4, unlike the present one, must be ordered by the court, it was still considered to be "voluntary ... [because it] must be predicated upon a clear, unequivocal and express intent to abandon an action. Such intent must be demonstrated to the court by way of a motion to dismiss, stipulation of the parties or some other form of express intent on the record." (Kaufman & Broad Bldg. Co. v. City & Suburban Mortg. Co. (1970) 10 Cal. App.3d 206, 213 [88 Cal. Rptr. 858].) There is no reason to treat the dismissal in this case any differently. It, too, was obtained after the commencement of trial, but by the simple expedient of an "oral ... request to the judge...." (Former Code Civ. Proc., § 581, subd. 5.) It was voluntary for the purposes of Civil Code section 1717.[1]
Judgment affirmed. Each party shall bear its own costs on appeal.
Trotter, P.J., and Sonenshine, J., concurred.
NOTES
[1]  As an aside, we note leading commentators invariably list, albeit with very little discussion, a former section 581, subdivision 5 dismissal as an example of the "voluntary" variety. (See, e.g., 6 Witkin, Cal. Procedure (3d ed. 1985) Proceedings Without Trial, § 69, p. 380 and Cal. Practice Guide, Civ. Procedure Before Trial (The Rutter Group 1985) § 11:28.)
