Repeating data from a JOBJECT

Asked

Viewed 73 times

0

I managed to make my JArray return a list, in this list contains 03 Ids, but the way the system was done, they made a way to return only the first Array.

Follows the code of what is returning to the View:

[HttpPost]
public PartialViewResult DadosUser2(ListaUsers user_IDs)
{
    UserBLL bll = new UserBLL(context.db);
    JArray users = bll.DadosUser2(user_IDs.user_ids);

    if (users.Count == 0)
        throw new Exception("Usuário não encontrado user_id " + user_IDs);

    JObject u = (JObject)users[0];

    return PartialView("DadosUser", u);
}

How can I do this JObject return all data and not only the first position?

  • Why not return all the Array? That is to say: return PartialView("DadosUser", users);.

  • That line JObject u = (JObject)users[0]; is making return only the first. Take it out and put only return PartialView("DadosUser", users);

  • when making this report that you suggested arises error Error code: PX100 Message: Cannot convert type 'Newtonsoft.Json.Linq.Jarray' to 'Newtonsoft.Json.Linq.Jobject'

  • That’s because your View is only expecting a Jobject, you have to change in your view to accept a Jarray

1 answer

0

The line below is only returning the first:

JObject u = (JObject)users[0];

Do:

[HttpPost]
public PartialViewResult DadosUser2(ListaUsers user_IDs)
{
    UserBLL bll = new UserBLL(context.db);
    JArray users = bll.DadosUser2(user_IDs.user_ids);

    if (users.Count == 0)
        throw new Exception("Usuário não encontrado user_id " + user_IDs);

    return PartialView("DadosUser", users);
}
  • This has been done and it’s been wrong...

  • Yes, and Julio Borges replied. The same type sent from the controller has to be the same received by the view. Before you sent a JObject, now it’s sending a JArray. Change the received type in the view to JArray

Browser other questions tagged

You are not signed in. Login or sign up in order to post.