How to calculate the very next position on a NavMesh to a cast ray outside the NavMesh?

The situation is: I have a world with a NavMesh attached to it. If I click somewhere in the world the NavMeshAgent moves the character as near as possible to the clicked position. Fine. But the problem is that the Physics.Raycast()-function returns false if I click somewhere outside my “world”. Ok that’s fine, too. But my question is now how to get the very next position on my NavMesh to the cast ray.

            // Collect all mouse click data.
            MouseClickData data = new MouseClickData();

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                data.WorldPosition = hit.point;
                data.ClickedObject = hit.collider.gameObject;
            }
            data.ScreenPosition = Input.mousePosition;

I’ve tried putting a invisible plane under “my world”. This approach works more or less well for clicks next to “my world”, but clicks far away seem to be thrown away. At least the character (or the NavMeshAgent) doesn’t move. An other disadvantage is that the camera always needs to be positioned carefully because otherwise there would be a chance having “empty space” again.

I’ve also tried to put “my world”, including the camera, completely inside a sphere collider, but this doesn’t work at all because sending a ray will result in getting an answer immediately as we are already inside a collider.

My current solution is casting a ray from mouse position on screen to the scene. If the ray hits something, everything is fine and the character moves as near as possible.
Otherwise I check for every point of the ray the nearby colliders, find the closest collider and save its distance to the point. After all I know the distances of all points to their closest collider. I take the point with the shortest distance, get its closest collider and move the character to a collider’s point which lies next to the point of the ray.
This approach results in moving my character relatively precisely to a position I would expect. But the algorithm might have performance issues.

So I solved my problem myself. Anyway, thank you for trying to help me. But if you have some further ideas for optimization, just let me know it.