I have my view like so on my .cshtml page:
@{ var counter = 0; }
@foreach (var item in Model){
@Html.TextBox("name_" + @counter, item.name,
new {
@class = "form-control",
@onkeyup = "myFuncWithRazorCounter('My Counter: ' + @counter)"
})
{ counter = counter + 1; }
}
@section scripts
{
<script type="text/javascript">
function myFuncWithRazorCounter(counter){
var myCounter = counter;
console.log(myCounter);
}
</script>
}
Let's say my Model count is 10.
When I call the function from the onkeyup event listener by typing into the textbox id of name_8, how can the counter get passed through and into myFuncWithRazorCounter() function?
End result I would like to see in the console is: My Counter: 8