You are correct that you need to store the date into a JS variable. Something like this:
<script>
var datePart = '@ViewData["projectStartDate"]';
</script>
Of course I'm assuming that the ViewData
value is already formatted into a string format that JS likes. If not then you'll need to do the conversion as part of the server-side logic in the script tag. The end result in JS would be something like this:
<script>
var datePart = '1/2/2021';
</script>