Ampere's Law

Homework Statement

I want to know why Ampere's Law can sitll be applied/valid if the Amperian surface is drawn as a rectangle which encloses a whole solenoid. Normally the rectangle would just include one side of the solenoid.

The Attempt at a Solution

When only one side of the solenoid is enclosed, Ampere's Law will work because B and ds will be parallel on the side of the rectangle which is inside the solenoid so we can intergrate this to an non-zero value. But I'm confused about when the whole solenoid is enclosed by the rectangle. It is an ideal solenoid so there should be no magnetic field outside the solenoid so the integral of the 2 sides which are parallel to B will be 0. The other two sides are perpendicular to B so they will also = 0. The only reason I can think that Ampere's Law still applies is that all of the current is enclosed so that somehow helps with the solution?

I'm really stuck here, because I keep getting the left side of the equation =0 so I cannot see how the law is still valid.