R
R
Roman Zhidkov2016-04-15 13:22:19
JavaScript
Roman Zhidkov, 2016-04-15 13:22:19

How to pass the value of an ASP.NET variable to a java script variable?

Good!
I try like this, I crash with an error:

@model Events

<script>
    var date = @Model.date;
</script>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
SecurityCodeNAS, 2016-04-15
@VigVam

If try
var date = '@Model.date'

I
Ivan Filatov, 2016-04-15
@NYMEZIDE

Please provide the controller code.
Like this, are you passing your model to the View?

public ActionResult Index()
{
...
View("Index", myModel);
}

P
Peter, 2016-04-15
@petermzg

If you need to get as an object, then like this:
var dppts = @Html.Raw(Json.Encode(@Model.depth));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question