Atomically thin MoS2 has recently emerged as a very attractive material for nanoscale optoelectronic devices. While n-type transport in MoS2 devices has been demonstrated, hole conduction has been more challenging. Here we show work-function engineering to be an effective approach for controlling the polarity of MoS2 devices. Gated multi-layer MoS2 transistors with Au source/drain contacts exhibit n-type operation, while those with Pd contacts are shown to have p-type behavior. Devices with one Au and one Pd contact exhibit asymmetric ambipolar behavior and diode characteristics over a wide range of gate voltage, as well as a sizable photovoltaic effect. We argue that the photovoltaic effect arises from the built-in potential of the space charge accumulated at the source and drain contacts.