Iterating throgh mvc model lists using javascript

Posted by kapil on Stack Overflow See other posts from Stack Overflow or by kapil
Published on 2010-05-04T09:48:00Z Indexed on 2010/05/04 9:58 UTC
Read the original article Hit count: 503

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about asp.net-mvc