in my MVC View I would like to do something like limiting model objects only to objects which property "Date" is greater than date from input calendar.
In scripts sections in function drawChart()
I have added
var start = new Date(document.getElementById("start").value);
but when I try to get this this value I get an error "The name ‘start’ does not exists in the current context". This is what I want to do:
var start = new Date(document.getElementById("start").value);
var test = @Model.Where(s => s.Date > start)
var data = google.visualization.arrayToDataTable([
['Date', 'Entries'],
@foreach (var obj in test)
{
<text> [new Date(@obj.Date.Year, @obj.Date.Month - 1, @obj.Date.Day), @obj.Count], </text>
} ]);
How should I do it?
3
Answers
As Jack explained you are trying to access a javascript variable (which is client side) within vs code (which is server side). Every expression that is adjacent to a @ sign compiles at server side. You may send that date variable from client to server by putting it in a html form element, then submit it to the pagemodel.
try viewbag instead, i tried something like that in my code, and it worked fine.
in your code try doing it like this:
Try this it worked for me. Thanks