iMac Will not Recognize its HDD
I just had a hdd fail in my imac last week. So I know this method works:

Get all important files off of the hdd with Lazesoft Mac Data Recovery. You'll have to copy the files to another disk. If you have enough space, the one you used to boot with might be enough. It takes a LONG time to copy files off of a disk that will not mount in the OS! Be patient.

From there it's up to you. Personally I'd replace the failed drive. If it failed once, it will fail again. But if you have the luxury of time and patience, you can try to erase/reformat it yourself then copy the files back... hope for the best.

Otherwise, take it to Apple. They'll replace the drive and copy the data for you (if possible). They'll also break your bank =) They won't even give you a price over the phone!

I went with UBreakIFix. $100 got the replacement done. But I had to copy the files myself as described above. Also they didn't do the jumpers right so the fans come on at 100% until I put in a software solution to fix that. A lackluster experience for sure. But if you go in there with the knowledge of the SMC/fan situation, they'll probably set it up correctly for you.