Return more than one data list in the view

Asked

Viewed 594 times

1

In my Return View(), is there a way for me to return two or more lists? These lists are the result of a.

  • Yes @pnet. You can return as Viewbag or as Viewdata, then just go through the view ;)

  • There are differences between them, like performance, "easier to work", more elegant, anyway, there is difference? When to use one or the other?

  • Both are accessible to work, now in performance I can not tell you which is the best. But I believe that there is not much difference

1 answer

0


You can put in Viewbag

ViewBag.Lista1 = new List<>();
ViewBag.Lista2 = new List<>();

return View();

Then the View Voce accesses in the same way:

@ViewBag.Lista1

Now Voce can if you want, create a class c# Viewmodel that is "wrapper" by joining the two lists in a new class

return View(new MyViewModel{ Lista1 = new List<>(), Lista2 = new List<>() });

Then the View Voce accesses:

@Model.Lista1

Sack ?

  • I saw this example net and am now seeing how to do to meet my need

Browser other questions tagged

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