Bring a large pot of salted water to a boil. Cook the mostaccioli according to package directions until al dente. Drain and set aside.
In a large skillet, heat olive oil over medium heat. Add the chopped onion and cook until softened, about 3 minutes. Stir in the garlic and cook for another 30 seconds. Add the ground beef or sausage and cook until browned. Drain excess fat.
Stir in the marinara sauce and Italian seasoning. Simmer for 5 minutes. Season with salt and pepper to taste.
In a large mixing bowl or the pot used to boil pasta, combine the cooked pasta with the meat sauce. Stir until evenly coated.
Preheat the oven to 375°F (190°C). In a greased 9x13-inch baking dish, layer half the pasta mixture, dollop with half the ricotta, and sprinkle with half of the mozzarella and Parmesan. Repeat with the remaining ingredients.
Cover the dish with foil and bake for 20 minutes. Remove the foil and bake an additional 10 minutes until the cheese is melted and bubbly.
Let the casserole rest for 5–10 minutes before serving. Garnish with fresh basil or parsley, if desired.