Fixed after I added this script in the head tag of my cshtml file:
<script type="module">
import RefreshRuntime from "http://localhost:5173/@@react-refresh"
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
</script>
I was getting the "Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong." Vite server error since I wasn't importing the refresh runtime that the Vite server provides to allow HMR.