How to send value from model in view to javascript file?

In MVC, How can I send value from model in view to javascript file? 

Asked by:- DanielNguyen
: 3629 At:- 7/19/2017 7:07:10 AM
MVC javascript

Daniel, can you elaborate your question? With some code or more details 0
By : pika - at :- 7/19/2017 8:06:22 AM

1 Answers
profileImage Answered by:- vikas_jk

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


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)

At:- 7/19/2017 10:44:18 AM Updated at:- 7/19/2017 10:53:41 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use