
696 N.E.2d 1196 (1998)
231 Ill.Dec. 625
MUCH SHELIST FREED DENENBERG AND AMENT, P.C., Plaintiff-Appellant,
v.
John M. LISON, an Individual, and Lison and Griffin, a Partnership, Defendants-Appellees.
No. 1-97-2792.
Appellate Court of Illinois, First District, Fourth Division.
June 11, 1998.
*1197 Much Shelist Freed Denenberg Ament Bell & Rubenstein, P.C., Chicago (Michael J. Freed, John H. Ward; Peter D. McWeeney, of counsel), for Plaintiff-Appellant.
Lison & Griffin, P.C., Chicago (Alan L. Garrow, of counsel), for Defendants-Appellees.
Presiding Justice CERDA delivered the opinion of the court:
Plaintiff, Much Shelist Freed Denenberg & Ament, P.C., a law firm, appeals from the entry of summary judgment by the circuit *1198 court of Cook County on its complaint in favor of defendants, attorney John M. Lison and Lison & Griffin, a law firm partnership (L & G), for the quantum meruit value of plaintiff's legal services representing L & G as the class representative in a class-action lawsuit that defendants abandoned.
The issue is whether, under a contingency-fee agreement, plaintiff law firm can recover the quantum meruit value for its services rendered before the client discharged it, although there was no recovery. Defendants believed there was no likelihood of success because the complaint had been dismissed once on a section 2-615 motion (735 ILCS 5/2-615 (West 1996)). L & G withdrew as class plaintiff and refused to pay for legal services because the plaintiff had not obtained any recovery in the class-action lawsuit. We reverse.

FACTS
In June 1992, Regent Advisory Corporation filed a class-action lawsuit in the circuit court of Cook County against Equitec, which was Regent's landlord at the building located at 200 West Adams Street in Chicago. The original class-action complaint is not in the record, but the parties agree that it alleged the landlord billed its tenants for an amount of real estate taxes that the landlord did not pay. Plaintiff and L & G were both attorneys representing Regent, but L & G withdrew as attorney after the trial court suggested that L & G could not act as a class member and as co-counsel. Because Regent withdrew as plaintiff, in September 1992 the action was dismissed with prejudice only with respect to Regent but without prejudice to the other potential class members.
In September 1992, the class action was refiled with L & G, which was also a tenant in Equitec's building, now as the plaintiff. Plaintiff had signed a written contingency-fee agreement with Regent, but plaintiff failed to obtain L & G's signature on a contingency-fee agreement for plaintiff's representation of L & G. The parties on appeal agree that there was a contingent-fee agreement between them.
On October 14, 1992, Equitec filed a motion to dismiss the second class action pursuant to section 2-615 of the Code of Civil Procedure (735 ILCS 5/2-615(a)(West 1996)). The trial court granted the motion on January 21, 1993. The trial court first stated that the motion would be granted with prejudice because it was doubtful that plaintiff could file an amended complaint that could withstand a motion to dismiss but, after argument of counsel, the court changed its mind and granted the motion without prejudice. The complaint was amended a third time on February 26, 1993.
On July 14, 1993, L & G signed a general release of its claims with the class-action defendants for consideration of entering into a new lease. Because L & G withdrew as class plaintiff, on July 23, 1993, Equitec moved to dismiss the class action. On September 15, 1993, the trial court granted the motion to dismiss the action with prejudice to L & G and without prejudice to other potential class members.
On September 16, 1993, plaintiff filed a complaint against defendants for attorney fees. Count I of plaintiff's complaint was for breach of contract; count II was for quantum meruit; and count III was for unjust enrichment. Count I was dismissed on July 13, 1994.
On August 13, 1996, defendants filed a motion for summary judgment, arguing in part that (1) plaintiff was not entitled to any compensation on a contingent-fee matter because there was no evidence that the underlying case had any reasonable prospect of success and no reasonable chance of success on appeal; (2) plaintiff could not recover under quantum meruit because plaintiff's services were not of any value to L & G where no cause of action could be stated in the class action; and (3) L & G did not receive any recovery or economic advantage as a result of plaintiff's activities and merely negotiated a new lease with the new management, who executed leases with other tenants at about the same rent or lower than L & G's rent.
On January 17, 1997, the trial court granted summary judgment on the quantum meruit count in favor of defendants and denied *1199 summary judgment on the unjust-enrichment count.
On July 1, 1997, count III, the unjust-enrichment count was voluntarily dismissed without prejudice; plaintiff's motion to reconsider the ruling with respect to the quantum meruit count was denied. On July 10, 1997, the order was amended to find that there was no just reason for delaying enforcement or appeal of the order granting defendants' motion for summary judgment on the quantum meruit count and of the order denying plaintiff's motion to reconsider.
On July 14, 1997, plaintiff appealed from the entry of summary judgment.

DISCUSSION
Plaintiff argues on appeal that it was entitled to be paid on a quantum meruit basis for the legal services it rendered to defendants because L & G abandoned the class-action lawsuit before plaintiff could file another amended complaint that could withstand a motion to dismiss. Defendants argue that plaintiff is barred from recovery because the class action had no reasonable prospect of success and because there was no value to L & G of the legal services provided by plaintiff.
A motion for summary judgment is to be granted if "the pleadings, depositions, and admissions on file, together with the affidavits, if any, show that there is no genuine issue as to any material fact and that the moving party is entitled to a judgment as a matter of law." 735 ILCS 5/2-1005(a) (West 1996). The pleadings, depositions, admissions, and affidavits on file must be construed against the movant and in favor of the opponent of the motion. Jackson Jordan, Inc. v. Leydig, Voit & Mayer, 158 Ill.2d 240, 249, 198 Ill.Dec. 786, 633 N.E.2d 627 (1994). Summary judgment is a drastic means of disposing of litigation, and the right of the moving party to obtain summary judgment must be clear and free of doubt. Jackson, 158 Ill.2d at 249, 198 Ill.Dec. 786, 633 N.E.2d 627. The reviewing court's function is to determine de novo whether the judgment entered was correct as a matter of law. Cates v. Cates, 156 Ill.2d 76, 78, 189 Ill.Dec. 14, 619 N.E.2d 715 (1993).
A client may discharge her attorney at any time, with or without cause. Rhoades v. Norfolk & Western Ry. Co., 78 Ill.2d 217, 227-28, 35 Ill.Dec. 680, 399 N.E.2d 969 (1979). When a client terminates her attorney, the contingent-fee contract ceases to exist, and the contingency term is no longer operative. In re Estate of Callahan, 144 Ill.2d 32, 40, 161 Ill.Dec. 339, 578 N.E.2d 985 (1991).
A discharged attorney may be compensated for the services rendered before the discharge on a quantum meruit basis. Rhoades, 78 Ill.2d at 230, 35 Ill.Dec. 680, 399 N.E.2d 969. Quantum meruit literally means "as much as he deserves." First National Bank v. Malpractice Research, Inc., 179 Ill.2d 353, 365, 228 Ill.Dec. 202, 688 N.E.2d 1179 (1997). In quantum meruit recovery, the former client is liable for the reasonable value of the services received during the attorney's employment. Callahan, 144 Ill.2d at 41, 161 Ill.Dec. 339, 578 N.E.2d 985. Quantum meruit is based on the implied promise of a recipient of services to pay for valuable services because otherwise the recipient would be unjustly enriched. Callahan, 144 Ill.2d at 40, 161 Ill.Dec. 339, 578 N.E.2d 985.
In Illinois, the attorney's action for a quantum meruit fee accrues immediately after discharge, in comparison to some other jurisdictions, which hold that an attorney's cause of action for fees does not accrue until the recovery in the lawsuit, which is the contingency stated in the fee agreement. Callahan, 144 Ill.2d at 38-39, 161 Ill.Dec. 339, 578 N.E.2d 985. Under the reasoning of these other jurisdictions, where a contingent-fee agreement was entered into, the attorney who is discharged before recovery cannot recover fees. E.g., Life Care Centers of America, Inc. v. Chiles, 674 So.2d 873, 874 (Fla.Dist.Ct.App.1996)(recovery was denied to a class-action attorney, after the client withdrew, on the basis that the contingency of recovery in the class action never occurred).
*1200 In Illinois a discharged attorney may recover on a quantum meruit basis a reasonable fee for services rendered before discharge. Rhoades v. Norfolk & Western Ry. Co., 78 Ill.2d 217, 230, 35 Ill.Dec. 680, 399 N.E.2d 969 (1979). The Callahan court stated that even though a contingency fee is generally paid out of the recovery for the client, when a client terminates a contract, the contract ceases to exist between the parties. Therefore, the contingency term, whether the attorney wins, is no longer operative. Callahan, 144 Ill.2d at 40, 161 Ill.Dec. 339, 578 N.E.2d 985. The client cannot terminate the agreement and then resurrect the contingency term when the discharged attorney files a fee claim. Leoris & Cohen v. McNiece, 226 Ill.App.3d 591, 596, 168 Ill.Dec. 660, 589 N.E.2d 1060 (1992). Quantum meruit is based on the implied promise of the recipient of services to pay for those services that are of value to him. Ashton v. County of Cook, 384 Ill. 287, 301, 51 N.E.2d 161 (1943).
In some cases, it is possible for a client to receive services and yet not be enriched in a tangible way. D. Dobbs, Handbook on the Law of Remedies § 4.2, at 237 (1973). That may have occurred in this case.
In the case of Ashby v. Price, 112 Ill.App.3d 114, 67 Ill.Dec. 958, 445 N.E.2d 438 (1983), the client discharged his attorney and argued that he should not have to pay the quantum meruit value of his attorney's services because no benefit was received. The court held that the lack of benefit should not prevent the attorney from recovery for the legal services rendered. Ashby, 112 Ill.App.3d at 122-23, 67 Ill.Dec. 958, 445 N.E.2d 438. We agree with the Ashby court. The lack of any value or benefit received by L & G from the legal services rendered by the plaintiff does not prevent the plaintiff from obtaining attorney fees on a quantum meruit basis.
We reject defendants' argument that whether there was a reasonable expectation that the class-action lawsuit would ever succeed is relevant to whether plaintiff can obtain attorney fees. Plaintiff's action accrued at the time of discharge, and the probable outcome of the litigation is not an indispensable element that must be considered in calculating the value of the discharged attorney's services. Callahan, 144 Ill.2d at 41, 161 Ill.Dec. 339, 578 N.E.2d 985.
Plaintiff was entitled to quantum meruit recovery. The trial court erred in granting summary judgment in favor of defendants, and we now enter summary judgment in favor of plaintiff.
Defendants argue in the alternative that plaintiff's recovery is barred because plaintiff violated Rule of Professional Conduct 1.5(c) (134 Ill.2d R. 1.5(c)), which requires that a contingent-fee agreement be in writing.
Defendants rely upon two cases that denied quantum meruit recovery for attorneys who were not allowed to recover fees under contracts that violated ethical canons. Leoris v. Dicks, 150 Ill.App.3d 350, 354, 103 Ill.Dec. 584, 501 N.E.2d 901 (1986); Licciardi v. Collins, 180 Ill.App.3d 1051, 1062-63, 129 Ill.Dec. 790, 536 N.E.2d 840 (1989). These cases were decided under the Code of Professional Responsibility, which was repealed effective August 1, 1990, and which was replaced with the Illinois Rules of Professional Conduct (Lee v. Ingalls Memorial Hospital, 232 Ill.App.3d 475, 477-78, 173 Ill.Dec. 773, 597 N.E.2d 747 (1992)).
In Leoris, 150 Ill.App.3d at 354, 103 Ill. Dec. 584, 501 N.E.2d 901, the attorney who entered into an unethical fee-splitting agreement, which violated public policy, was foreclosed from quantum meruit recovery because entering into the agreement also violated stated canons of ethics. The court relied on the principle that, where enforcement of an illegal contract is sought, the courts will aid neither party but will leave them where they have placed themselves so that the parties can recover nothing under the contract. Leoris, 150 Ill.App.3d at 354, 103 Ill.Dec. 584, 501 N.E.2d 901.
Licciardi, 180 Ill.App.3d at 1062-63, 129 Ill.Dec. 790, 536 N.E.2d 840, followed Leoris to bar quantum meruit recovery to an attorney who entered into an unethical contingent-fee contract for a dissolution-of-marriage action. The court rejected the argument that Leoris barred quantum meruit recovery only in fee-splitting cases. Licciardi, *1201 180 Ill.App.3d at 1062, 129 Ill.Dec. 790, 536 N.E.2d 840. The court explained that the public policy behind Disciplinary Rule 2-106(c)(4) is so important that, as long as an attorney's services are employed with respect to the division of marital property, the rule bars contingent fees therefor. Licciardi, 180 Ill.App.3d at 1061, 129 Ill.Dec. 790, 536 N.E.2d 840.
Licciardi and Leoris are distinguishable because in those cases it was prohibited for the attorneys to enter into the agreements at issue; the fee agreements themselves violated public policy. See Lee, 232 Ill.App.3d at 478, 173 Ill.Dec. 773, 597 N.E.2d 747 (reliance on Leoris is misplaced if an agreement between a client and an attorney does not violate public policy).
The cases involving unenforceable agreements, including Leoris and Licciardi, do not bar quantum meruit recovery whenever an ethical rule is not followed unless it involves public policy. The contingency-fee agreement to represent defendants in a class-action lawsuit against a lessor for excess billing of real estate taxes does not violate any public policy and is enforceable.
Other cases that have also denied quantum meruit recovery for attorney fees or other fees have also involved unenforceable agreements. E.g., First National Bank v. Malpractice Research, Inc., 179 Ill.2d 353, 366, 688 N.E.2d 1179, 228 Ill.Dec. 202 (1997) (a contingency-fee agreement with an expert-search firm was unenforceable); American Home Assurance Co. v. Golomb, 239 Ill.App.3d 37, 44, 179 Ill.Dec. 961, 606 N.E.2d 793 (1992) (a contingency-fee agreement was valid for the type of case but contained an illegal contingent-fee percentage because the attorney engaged in intentional and deceptive behavior).
There have been cases that have permitted quantum meruit recovery even where the attorneys violated statutes concerning the attorney-client agreement or concerning fees.
Valenti v. Swanson, 294 Ill.App.3d 492, 228 Ill.Dec. 956, 690 N.E.2d 1031 (1998) (attorney failed to comply with the Personal Injury Representation Agreement Act (815 ILCS 640/0.01 et seq. (West 1996)) by not giving the clients a copy of the Act); Anderson v. Anchor Organization for Health Maintenance, 274 Ill.App.3d 1001, 1006, 211 Ill.Dec. 213, 654 N.E.2d 675 (1995) (a contingent-fee agreement contained an attorney fee provision in excess of the maximum percentage an attorney could receive without court approval, in violation of section 2-1114 of the Code of Civil Procedure (Ill.Rev.Stat.1987, ch. 110, par. 2-1114)).
Whether quantum meruit recovery is barred should depend on the egregiousness of the particular conduct involved. See Anderson, 274 Ill.App.3d at 1006, 211 Ill.Dec. 213, 654 N.E.2d 675 (whether a violation of section 2-1114 of the Code of Civil Procedure is sufficiently egregious to render the contract wholly unenforceable must be decided in the context of the particular facts). Whether an attorney acted egregiously should be a matter for the trial court to determine in its discretion. See Anderson, 274 Ill.App.3d at 1007, 211 Ill.Dec. 213, 654 N.E.2d 675 (whether a discharged attorney who contracted for a contingent fee in excess of the rate set forth in section 2-1114 of the Code of Civil Procedure may recover in quantum meruit is a matter committed to the discretion of the trial court). We find that plaintiff's lapse in not obtaining the signature of L & G, which was a law firm and therefore knowledgeable of its right to get a written agreement, was not sufficiently serious to taint plaintiff's lawsuit for quantum meruit recovery.
Defendants also argue that plaintiff's action is barred by res judicata because the trial court ruled in the class action that plaintiff had no attorney lien and because plaintiff could have sought attorney fees in the class-action lawsuit.
The doctrine of res judicata provides that a final judgment on the merits rendered by a court of competent jurisdiction bars a subsequent action involving the same claims or demands by the same parties. People ex rel. Burris v. Progressive Land Developers, Inc., 151 Ill.2d 285, 294, 176 Ill.Dec. 874, 602 N.E.2d 820 (1992). Res judicata also applies to matters that could have been decided in the prior action. Progressive, *1202 151 Ill.2d at 294, 176 Ill.Dec. 874, 602 N.E.2d 820.
We reject defendants' claim of res judicata because the present lawsuit does not have the same parties and the same cause of action as the class-action lawsuit.
When L & G withdrew as class plaintiff in the lawsuit in July of 1993, it terminated the contingency-fee agreement with the plaintiff law firm. The contingency-fee contract ceased to exist, and L & G became liable to the plaintiff for the quantum meruit value of plaintiff's legal services up to and including the date of termination. Plaintiff's right to recover on a quantum meruit basis accrued immediately upon L & G's settlement of the case and dismissal of its cause of action. Even though there was no recovery, no economic advantage was obtained, and the underlying case may have had no reasonable prospect of success, L & G must pay a reasonable fee for the legal services rendered. It is not a defense for defendants to argue that there was no value to the legal services provided and therefore they do not have to pay anything. L & G terminated the contract.
The judgment of the trial court is reversed; summary judgment is entered in favor of plaintiff against defendants on the issue of liability; and the cause is remanded for a determination of the amount of attorney fees to be awarded to plaintiff on a quantum meruit basis.
Reversed and remanded.
WOLFSON and SOUTH, JJ., concur.
