In asp.net MVC, How can I send value from model in view to javascript file?
I assume you have a javascript file with a function
function myFunc(value) {
var x= value;
}
to send value from Model to this function you need to create a script in view to call it
<script>
myFunc(@Model.Value);
</script>
Or another method to send value from model to javascript file is to directly convert the model to JSON object, then you can use it in your js file. The code as below:
var object = @(Html.Raw(Json.Encode(Model)));
That's it, hope it will help you, please upvote the answer and mark it as answer (if it works for you, and you have two votes for answer)
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly