Preheat your oven to 350°F (175°C). Cook spaghetti according to the package instructions until al dente. Drain and return to the pot. Toss with olive oil to prevent sticking.
Cook the Meat:
In a large skillet over medium heat, cook the onion and garlic until softened, about 3-4 minutes. Add the ground beef, breaking it apart with a spoon, and cook until browned. Drain any excess fat.
Combine Meat and Marinara Sauce:
Stir the marinara sauce and Italian seasoning into the skillet with the beef. Season with salt and pepper to taste. Simmer for about 10 minutes.
Mix Spaghetti and Sauce:
Add the cooked spaghetti to the sauce and toss to combine. Transfer half of the spaghetti mixture to a greased 9x13-inch baking dish.
Add Cheese Layer:
Sprinkle half of the Parmesan and mozzarella cheeses over the spaghetti in the dish. Repeat layers with the remaining spaghetti mixture and cheeses.
Prepare Egg Mixture:
In a small bowl, whisk together the egg and milk. Pour this mixture evenly over the top layer of spaghetti.
Bake:
Cover the dish with aluminum foil and bake in the preheated oven for 30 minutes. Remove the foil and bake for an additional 10-15 minutes, or until the cheese is bubbly and lightly browned.
Garnish and Serve:
Let the baked spaghetti stand for a few minutes before serving. Garnish with chopped fresh parsley if desired.