0

I tried to insert the value of a property of my model into a javascript variable, but it didn't work.

I tried the following:

 <script type="text/javascript">
    var sample = "@(Model.MyProperty)";
 </script>

 <script type="text/javascript">
    var sample = "@Model.MyProperty";
 </script>

 <script type="text/javascript">
    var sample = @Model.MyProperty;
 </script>

 <script type="text/javascript">
 @{
    var sample = Model.MyProperty;
  }
 </script>
1
  • are you sure that this markup isn't valid or other contruction don't intefere? Seems just fine. Commented Apr 20, 2012 at 10:22

1 Answer 1

2

This one should work

<script type="text/javascript">
    var sample = "@Model.MyProperty";
</script>

What is the error you are getting?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, was a viewmodel issue (30 minutes looking at the wrong place) :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.