<%: Html.HiddenFor(model => model.Name) %>
<script>
var name = <%: Model.Name %>
alert(name);
</script>
答案 0 :(得分:10)
您需要在值周围加上引号,以便将其视为字符串:
var name = '<%: Model.Name %>';
alert(name);
但是如果你已经在隐藏字段中有值:
<%: Html.HiddenFor(model => model.Name) %>
你可以这样读:
var name = document.getElementById('Name').value; // make sure the id is Name
alert(name);
或使用jquery:
var name = $('#Name').val();
alert(name);