I've never really noticed the similarities between these two books before, but re-reading them one after the other made it in fact very pointed. (It's worth noting, I really really like the first two parts of the first Foundation novel, and struggle to remember the second two, so this is just about the first half :)
In Dune, initially Paul, and later Leto, are somewhat hamstrung by their prescience. Paul abandons everything, unable to face the future he knows is coming, unwilling to be what his foresight is forcing upon him with the "Golden Path" that is the only one of all the possible futures that doesn't lead to the destruction of humanity. Leto, on the other hand, embraces the path, knowing that it will require him to effectively become as evil as possible, put a stranglehold (temporarily) on humankind, and be both worshipped as a god and hated as much as a devil. Because it is the only path, and simply seeing the path in fact creates it.
In Foundation, Hari Seldon's plans take on a similar scope, but approaches it in an almost opposite way. Instead of prescience we have "psycho-history", which is sort of a super advanced psychological profile of the human race, combined with the sociology of large groups and some rockingly big mathematical equations. The result is essentially the same; Hari, and his small group, know what's coming. It's inevitable, and will plunge humanity into a dark age that will last 30 thousand years - unless matters can be bent to stick to the Seldon plan, in which case while the dark age will still happen, it'll be done with in just one thousand years, and a galactic renaissance can occur.
The divergence from Dune though: knowing what's coming, allows free will to take over, the possibility of responses multiply. In fact, saving humanity and providing the resources for a renaissance after an inevitable fall into barbarism, requires that nobody know what's coming so they are periodically forced into corners that Hari and co predicted, and that when those crises come, they have only one plan of action remaining to them. If they knew, things would change, they'd avoid the crisis, they'd plan for it, they'd have alternatives... and the thousand year long prediction would fall apart, and with it the plan.
It's interesting to me that the more or less mystical prescience given to Paul, and backed by established religion in his world, leads him to reject it. He won't be the leader of a jihad, he won't become a god to his people. Except that's exactly what he ends up doing, no matter how much he wishes he could choose differently. And when his prescience fails him, he gives up completely. Conversely Salvor Hardin in Foundation, who is to my mind the inheritor of Seldon's great plan and the most fun character in the book, worries constantly that he knows too much about the plan, and he'll inadvertently undermine it by accidentally planning his way out of a required and foreseen crisis. And one of his solutions to one of these crises, is in fact to create a false religion, in order to keep certain knowledge (in this case, science... all of it) out of the hands of the people of now, but safe for the future.
Paul doesn't want to be a religious figure, but is forced to be by circumstance, and hates himself for taking advantage of it, while Hardin creates the same circumstances by setting himself up as the high priest of a false religion, and almost gleefully taking advantage of it. And in context, perhaps you could say both are the right and only path for those characters to take.
I really have no point to this comparison, I just found it interesting.