views:

33

answers:

2

hello friends,

i have

public jsonresult update(studentinfo s)
{

  for(i=0;i>0;i++)
  {
     var x = // i am getting some x so i am checking again 

     if( x != null)
      {
        var updateuser = student.update(s.student,"","");
        **return json(updateuser.ToString());** // if i keep it here i am getting exceptoin  saying not all code paths return value bec this return i can not keep it out for loop bec each and evary updateuser i need to return json..
      }
  }

}

how to overcome this type of things? thanks

+1  A: 

If I understand correctly, you want to return a collection of users. The 'return' keyword does not work like that. You need to return the entire collection at once.

mgroves
yes.. but here i am returning each updated user once..thanks
kumar
no, you are returning only the first user (if it would compile anyway, but it won't because x could be null)
mgroves
+2  A: 

What language are you using to write your code? What you've posted doesn't look like any of the valid languages I know for .NET. Here's how the controller action might look in C# (assuming this is the language you are using):

public ActionResult Update(StudentInfo s)
{
    // create some collection that will contain all updated users
    var updatedUsers = new List<StudentInfo>();

    // Revise the loop as it is absolutely not clear from your code
    // what you are trying to do. The way you wrote the loop it will 
    // never execute - for(int i=0; i>0; i++)
    for (int i = 0; i < 5; i++)
    {
        var updatedUser = student.Update(s.student, "", "");
        updatedUsers.Add(updatedUser);
    }

    // return the list of updated users outside the loop so that the compiler 
    // doesn't complain about paths of the method not returning a value
    return Json(updatedUsers);
}
Darin Dimitrov