I have a .cshtml
file which I am using the model:
@model IEnumerable<WebApplicationMVCTest.Models.Test>
The model contains the parameter Date
(among other parameters). I access this value when creating a table:
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.SiteID)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date)
</td>
...
I have a function in my code NotTested
and I want to pass the item.Date
value into the function as one of the arguments:
<script>
document.onload = NotTested("Site 001", item.Date);
function NotTested(SiteId, TestDate) { ... }
</script>
The problem is two-fold. 1) I know that the Date is part of the model in this view so that it is present onload
when the function is called, but 2) the model
is out of context in the <script>
section of code.
I know that item
is not present onload
since this is is only transient for the for loop. I have just used item.Date
as a placeholder argument.
How do I get access to this when calling the function?