The major national parties know whom is registered with to whatever political party. There is no secret about it - most of this is public record available.
When the voter goes to the polls - or in our case locally, returns their mail-in ballots, it is not known who voted for whom or whatever. Once the ballot is removed from the signed affidavit envelope the ballot carries absolutely no identification in regards to an individual or their political preferences.
We keep record of 'who' voted, mainly for obvious reasons to prohibit multiple ballots from the same person, even if they live in another state. They only must have a residence within the county in order to qualify to vote - their mailing address can be most anywhere in the country. Same is true for our infantrymen ... they are able to vote via email if they so choose.
Party information is not mandatory. When I see a new voter registration form that has not designated any political party affiliation, I code it "PND" (party not determined) and the voter will then not show up on any parties lists.
Like so many people around here we are tired of all the telephone calls from political parties. Close to an election they can call up to 10 or 12 times per day, anywhere between 8am and 9pm. And of course your snail-mail box also gets flooded with brochures, letters and placards from political parties.
I am registered as Independent. Independent is not a political party, rather a designation that I am not partial to any political preferences and choose not to be associated with any recognized political asset. I therefore do not get the barrage of phone calls nor the snail mail flooding.
I am not able to vote in the primary election ... but I can vote in the general elections. Works out fine for me.