Randomize different PartialViews at random

0

I have the following scenario: I have to pass to a view data of different tables (similar data, but without any relation), until then I got it good. I created a class (viewmodel) that receives the data, in the Controller food it when I give the return to the view, and in view I give a foreach in each property and inside that foreach I render the respective PartialView . So far so good.

However, I intend to "mix" these partialView , and do not first show the data of a property and after it all ends, go to another.

How would you display this in a "random" way? Or rather, what logic to display something "random"? Was it some for loop?

For more understanding, follow the ViewModel , Controller and View :

ViewModel

public class VideosManuaisIndex
{
    public IEnumerable<Video> Videos { get; set; }
    public IEnumerable<Manual> Manuais { get; set; }
}

Controller

public ActionResult Index()
{
    return View(new VideosManuaisIndex 
    { 
         Videos = db.Video.ToList().OrderBy(v => v.sistema),
         Manuais = db.Manual.ToList().OrderBy(m => m.sistema)
    });
}

View

<div class="vid-lista">
@foreach (var manual in Model.Manuais)
{
    @Html.Partial("_Manual", manual);
}

@foreach (var video in Model.Videos)
{
    @Html.Partial("_Video", video)
}
</div>
    
asked by anonymous 10.12.2015 / 17:42

1 answer

0

Well, you could create a For Loop , and go check if the values are null, I do not know if it's orthodox but would look something like:

@{

    var length = Model.Manuais.Count > Model.Videos.Count ? Model.Manuais.Count : Model.Videos.Count;

    for (int i = 0; i < length; i++)
    {
        if(Model.Manuais[i] != null)
        {
            Html.Partial("_Manual", Model.Manuais[i]);
        }

        if (Model.Videos[i] != null)
        {
            Html.Partial("_Video", Model.Videos[i]);
        }
    }
}
    
11.12.2015 / 12:36