Can a foreigner come to New Zealand to get married before applying for a partner visa?

Yes they can, they may apply for a Partnership-Based Temporary Visa Application and will need in future to be eligible for a visa application under the partnership category.