I personally prefer The Dark Knight Rises, but I loved them both. They had entirely contrasting tones despite both spawning from comic books - The Avengers taking the more comic book-esque route, while The Dark Knight Rises had a more realistic tone - and I think they both practically indisputably perfected what they were aiming for.
Although it had a few unnecessary fight scenes thrown in here and there (albeit I still enjoyed them because of aesthetically-appealing special effects and choreography garnishing them), The Avengers was still a fantastic movie in my opinion. One of my favorite aspects of the movie besides the aforementioned combat was the struggled amongst the allies. Watching Captain America and Iron Man go at it and the Hulk attempt to contain his inner monster added a nice sense of realism instead of having the Avengers immediately get along and work together; of course, they found solidarity eventually, but that just added more to the excellent characters and their progression through the duration of the film. Also, Loki was a great villain to me, because my favorite antagonists are those that are both strong and intellectual. My only gripe besides the forced fight scenes was that I felt they spent a little too much time on the aircraft in the middle portion of the movie, but those parts were also enjoyable so I won't complain too much.
As for The Dark Knight Rises, after seeing it twice I have come to the conclusion that it is not only my favorite comic book movie, but my second favorite movie of all-time, falling just behind The Lion King and barely surpassing Rudy and The Dark Knight. It not only did what The Avengers did, but it was so much more than that; it was an uplifting story of rising from defeat to prevent cataclysm, and those elements were depicted in a very realistic fashion. The movie also had terrific characters, among which my favorites were John Blake and Bane. Bane was a terrific character in that, similarly to Loki, he had both intelligence and brute strength. I was sold on his character from the start when he wittily stated, "Maybe he's wondering why you would shoot a man before throwing him out of a plane" in that awesome voice of his and then viciously crashed the plane as he had planned; and from that point on he never came close to disappointment in my eyes. Another one of my favorite lines of his was when Daggett said he was in charge and Bane menacingly stared at him with his hand on Daggett's shoulder and said, "Do you feel in charge?" Furthermore, his incredible ability to test Batman to his breaking point (literally) was fun to watch, especially in the fight scene in Bane's lair. Now, with my fanboy-ing over Bane out of the way, John Blake was also great; I didn't need to have his real name revealed as Robin to detect the immense similarities between the two, and they definitely didn't go unappreciated by me; I especially liked seeing him take charge of the remnants of Gotham's good guys in Batman's five-month wake. And of course, Batman's character was excellent as well. Watching him go from recluse to Batman to the broken bat and back to Batman again was incredible and well-executed throughout the film's plot; him becoming Batman again and rising from the pit was incredibly inspiring, to both me and the people of Gotham. Alfred also shined with a few great monological attempts at convincing Bruce Wayne to move on in his life, and it all paid out at the end when he finally saw Bruce at the café in Florence. Finally, Anne Hathaway's Catwoman was by far the best yet in my opinion, despite having a few scattered cheesy lines; she also had great character progression.
And thus, that's why I prefer The Dark Knight Rises over The Avengers while loving both.