Iterating throgh mvc model lists using javascript
- by kapil
I want to iterate through my model values. Following is what I did to achieve this. But the varible count never increments. How can I increment it to iterate throgh my model values?
<script language="javascript" type="text/javascript">
function AddStudentName() {
var StudentName = document.getElementById('txtStudentName').value;
StudentName= StudentName.replace(/^\s+|\s+$/g, '');
if(StudentName!= null)
{
<%int count = 0; %>
for(var counter = 0; parseInt(counter)< parseInt('<%=Model.StudentInfo.Count%>',10); counter++)
{
alert('<%=count%>');
if('<%=Model.StudentInfo[count].StudentName%>' == StudentName)
{
alert("A student with new student name already exists.");
return false;
}
<%count = count +1;%>
}
}
}
</script>
thanks,
Kapil