mercredi 19 octobre 2016

For each page that shares the same tag in Razor

I have a method that adds a view every time the summary page is hit.

I need an if statement that says if a tag shares multiple pages to add the pageviews of that page and spit out the sum number.

for example. Page A, Page B, and Page C all have a relation to the tag "Happy". Page A has 2 pageviews, Page B has 3 page views, and Page C has 0 page views. This code should see that Tag "Happy" has the three related pages and add the numbers.

Problem is, my brain is doing 1+2 equals apple and I'm having a hard time sorting out what I need to write.

I think this needs to be done in Razor, and I have a code right now that gets all the tags.

What if statement do I need to write to make this work, and if not in Razor how do I write it into a valid method for and MVC public void?

Below is my Razor

@{
    ViewBag.Title = "Directory";
    var tags = new List<string>();
    foreach (var test in Model.Tests)
    {
        foreach (var tag in test.Tags)
        {
            if (!tags.Contains(tag))
            {
                tags.Add(tag);
            }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire