I am trying to assign a value from a Model into a JavaScript variable. But I have to check a condition before doing so.
Normally, I can assign values using this statement in script : var quantity = '@Model.Quantity'. It works, but I don't know how to do this inside an if loop, like-
<script>
@if (Model.Count == 0)
{
var quantity = 0;
}
else
{
var quantity = '@Model.Quantity';
}
</script>
But the statement inside the loop will be rendered as C#. So how do I achieve this ? I have to store the quantity into a JavaScript variable inside if loop.
Thanks :)