I am using ASP MVC 4 and jQuery. I want to get ViewModel properties from the javascript. I tried some solutions from stackoverflow, but none of them was working for me. Hope you Help me.
Thanks
I am using ASP MVC 4 and jQuery. I want to get ViewModel properties from the javascript. I tried some solutions from stackoverflow, but none of them was working for me. Hope you Help me.
Thanks
You can not access model properties from external JavaScript files so you have two options. You can include all of your JavaScript in the razor file as seen in the link below.
access model in javascript asp .net mvc razor
Otherwise you can set a global JavaScript variable and use it in your external file as seen below.
razor.cshtml
@model Order
<script>
var isEdit = '@Model.IsEditable'
</script>
externalfile.js
function getEdit() {
alert(isEdit);
}
@date