<%: Html.HiddenFor(model => model.Name) %>
<script>
var name = <%: Model.Name %>
alert(name);
</script>
You need to put quotes around the value so that it is considered as a string:
var name = '<%: Model.Name %>';
alert(name);
But if you already have the value inside a hidden field:
<%: Html.HiddenFor(model => model.Name) %>
you could read it like this:
var name = document.getElementById('Name').value; // make sure the id is Name
alert(name);
or using jquery:
var name = $('#Name').val();
alert(name);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With