Maxwell, Ch. J.
This is an action of ejectment, the defense being a general denial. Judgment in the court below was rendered in favor of Hunneman, who had been bjr order of court substituted as plaintiff in lieu of Doddridge, the original plaintiff. The errors assigned will be considered in their ■ order.
First. Objection is made to the admission of the deposition of W- B. Doddridge, upon the ground that it was taken in violation of an agreement, etc. The agreement was denied, and it is very clear that no advantage was taken of the plaintiff in taking the deposition, and it is proper evidence, There was therefore no error in its .admission. . ' •
Second. It is urged that the court erred in excluding the testimony of the plaintiff, as to the value of lasting and valuable improvements erected by him on the premises in controversy. It appears from the testimony that, the plaintiff took possession of the premises in the spring - of 1874, under a verbal lease from W. B. Doddridge; that he remained in possession as such tenant until March, 1877, *223at which time a proposition was made by Doddridge to Dale, offering to sell him the premises for the sum of §1,000, payable in county warrants. This proposition seems to have been accepted, the warrants to be delivered on or before July 1st, 1877. None of the warrants have ever been delivered, nor has the plaintiff paid any sum whatever for said premises. Nor does he now offer to comply with said contract in any manner or form. This being the case, the mere fact that the plaintiff had made valuable improvements upon the premises constituted no defense to an action for the possession. . If his case is within the provisions of the occupying claimants act, he may still apply for relief as to the value of such improvements.
Section 626 of the code provides that: “In an action for the recovery of real property, it shall be sufficient, if the plaintiff state in his petition that he has a legal estate therein, and is entitled to the possession thereof,” etc.
Section 627 provides that: “It shall be sufficient in such action, if the defendant in his answer deny, generally, the title alleged in the petition, or that he withholds the possession, as the case may be; but if he deny the title of the plaintiff, possession of the defendant will be admitted.”
The action of ejectment was originally devised to enable a tenant for years to recover the possession of the demised premises during the term, real actions at that time being confined to freehold estates. Blackstone says: “In order to maintain the action, the plaintiff must, in case of any defense, make out four points before the court, viz: title, lease, entry and ouster. First, He must show k good title in his lessor, which brings the matter of right entirely before the court; then that the lessor being seized or possessed by virtue of such title, did make him the lease for the present term;. Thirdly, That he, *224the lessee or plaintiff, did enter or take possession in consequence of such lease; and then, lastly, that the defendant ousted or ejected him.” 3 Blacks. Com., 202. The •form of the action was afterwards modified, so as to allow no question to be raised, except that of title and possession. And if the plaintiff was entitled to the possession, he could recover, whether the party in possession had ousted him or not. Under the code, to entitle the plaintiff to recover, he must possess a legal estate in the premises, and must state in his petition that he is entitled to the possession of the premises. Where the facts stated in the petition are denied, the plaintiff to be entitled to recover, must prove that he possesses a legal estate in the premises, and is entitled to the possession of the same. If the defendant possesses an equity which negatives the plaintiff’s right of possession, such equity may be proved under a general denial, as it is a mere defense to the action. But if the defendant seek affirmative relief, such as to enforce a contract which does not give him the right of possession, but does give him a right to demand a specific execution of the contract by the plaintiff, upon which the right to continue in possession of the premises depends, he must plead- the facts entitling him to such relief. And his answer must contain all the facts necessary to entitle him to such relief. In other words, he may set up in his answer the facts showing him to. have an equitable right to a conveyance from the plaintiff, and if he prove himself equitably the owner, and entitled to the possession, he will not only defeat the action, but obtain affirmative relief. In all eases where affirmative relief is sought by the defendant, the facts entitling him thereto must be set up in the answer. See Bliss on Code Pleading, sections 349-351. Dewey v. Hoag, 15 Barb., 365. Du Pont v. Davis, 35 Wis., 631. Estrada v. Murphy, 19 Cal., 248. Blum v. Robertson, 24 Id., 128, Bruch v. Tucker, 42 Id., 846.
*225The reason is, a counter-claim is an independent cause of action, in which the defendant becomes an actor in respect to his claim, and it is required to be stated with the same distinctness and certainty as in a petition. The evidence as to the value of the improvements was inadmissible under the pleadings, and was properly excluded. The judgment of the district court is clearly right and is affirmed.
Judgment Affirmed.