Pass a list to a view to get via Javascript

Asked

Viewed 73 times

1

I have a method Index, where it takes a parameter, makes a query and returns a list.

I need to run that list along with view or get that list some other way, so I can access list via Angularjs.

   public ActionResult Index(int id)
    {
        _check.NumberOfregistrationUser = id;

     // variável que guarda o resultado da minha consulta
       var list = GetUserByNumberOfregistration(_check.NumberOfregistrationUser);

        return View();
    }
  • 1

    You have several options there, but when working with Angularjs, you usually query the server data with HTTP calls. If this is the case you will need another action only to return the data to the customer. Otherwise, you can put the data in Viewbag or return them as a model of the view and serializar them there. For all the effects the last two options seem to me very bad and a bad use of a framework frontend as Angularjs. Well, for you to receive an answer, you need to [Dit] the question and clarify what you intend to do.

1 answer

1

public JsonResult MinhaLista(int id)
{
  _check.NumberOfregistrationUser = id;

     // variável que guarda o resultado da minha consulta
    var list = GetUserByNumberOfregistration(_check.NumberOfregistrationUser);

  return Json(new { nomeMeuObjRetorno = list  }, JsonRequestBehavior.AllowGet);
}

So you can access your list with Jquery, javascript or angular as a simple ajax call and get a return in obj.

Browser other questions tagged

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