San Francisco 49ers quarterback Trey Lance is feeling optimistic after undergoing surgery on his right ankle Monday morning, tweeting out that he’s ready to "attack this rehab process."

The second-year quarterback took to social media to share a photo of himself in a hospital bed after undergoing surgery to repair a broken bone and ligament disruption in his right ankle, an injury that will sideline him for the remainder of the season.

Trey Lance carted off

San Francisco 49ers quarterback Trey Lance gestures while being carted off the field during the first half against the Seattle Seahawks in Santa Clara, California, on Sept. 18, 2022. (AP Photo/Tony Avelar)

"Truly appreciate all of the messages and prayers. Surgery was a success and I am ready to attack this rehab process," he wrote in a tweet. "We will never understand why, but I trust that it’s all a part of His plan. I will be back better than ever. This chapter is going to make the story even greater!"

49ERS’ KYLE JUSZCZYK JOKED WITH JIMMY GAROPPOLO ABOUT BEING EMERGENCY QUARTERBACK 

Lance went down on the second drive of the game against the Seattle Seahawks on Sunday. He was carted off the field after what looked to be a gruesome injury.

"San Francisco 49ers quarterback Trey Lance underwent successful surgery on his injured right ankle this morning, an injury that occurred in yesterday's game versus the Seattle Seahawks," the team said in a statement.

Trey Lance writhes in pain

San Francisco 49ers quarterback Trey Lance lies on the field after being tackled during the first half against the Seattle Seahawks in Santa Clara, California, on Sept. 18, 2022. (AP Photo/Josie Lepe)

CLICK HERE FOR MORE SPORTS COVERAGE ON foxnews.1eye.us

"Surgery was performed to repair two injuries to Lance's ankle, a fibula fracture and ligament disruption. Lance will start the rehab process, and head team physician Dr. Tim McAdams is confident that he will recover completely in time for a full return in the 2023 season."

In the meantime, the Niners will rely on a familiar face to take over.

Jimmy Garoppolo and Kyle Juszczyk

Jimmy Garoppolo (10) of the San Francisco 49ers celebrates after Kyle Juszczyk (44) scored a touchdown against the Seattle Seahawks during the second quarter at Levi's Stadium in Santa Clara, California, on Sept. 18, 2022. (Thearon W. Henderson/Getty Images)

CLICK HERE TO GET THE FOX NEWS APP

"I don’t want to downplay what happened to Trey because we really do feel for him, but this is why you buy insurance," fullback Kyle Juszczyk said of quarterback Jimmy Garoppolo. "You don’t want to have to use it, but Jimmy was kind of our insurance policy."

The Associated Press contributed to this report.