I've created a web app where you can leave recommendations for a person, a person can have multiple recommendations, and got to the point where I'd like to view all recommendations for a particular Person. Once I click on the link to view the recommendations I get an error saying :
'KeyValuePair <`string, Recommendation> does not contain a definition for 'Recommendations' and no extension method 'Recommendations' accepting a first argument of type 'KeyValuePair' could be found.
Here's some of my code, hopefully someone can help me resolve this issue I've been stuck on for hours.
Recommendation Controller
using Lab3Models.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Lab3Models.Controllers
{
public class RecommendationController : Controller
{
private static IDictionary<string, Person> _people = null;
....
public ActionResult Show(string id)
{
if (Session["people"] != null)
{
_people = (Dictionary<string, Person>)Session["people"];
}
else
{
_people = new Dictionary<string, Person>();
Session["people"] = _people;
}
if (!_people.ContainsKey(id))
{
return HttpNotFound("Sorry, but can't find id: " + id);
}
return View(_people[id]);
}
}
}
public class Person
{
public string Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public ICollection<Recommendation> Recommendations { get; set; }
public Person()
{
Recommendations = new List<Recommendation>();
}
}
public class Recommendation
{
public string Id { get; set; }
public int Rating { get; set; }
public string Narrative { get; set; }
public string RecommenderName { get; set; }
public Person ThePerson { get; set; }
}
Show View
@model IDictionary<string, Lab3Models.Models.Recommendation>
<h2>@ViewBag.Title</h2>
<table class="table">
<tr>
<th>
Id
</th>
<th>
Rating
</th>
<th>
Narrative
</th>
<th>
Recommender's Name
</th>
</tr>
@foreach (var item in Model)
{
foreach (var rec in item.Recommendations)
{
<tr>
<td>
@item.Value.Id
</td>
<td>
@item.Value.Rating
</td>
<td>
@item.Value.Narrative
</td>
<td>
@item.Value.RecommenderName
</td>
</tr>
}
}
</table>
Please, any help would be great.
EDIT Iterating over a dictionary isn't my problem though, I've iterated through my person dictionary already to display all people I've added to the list. My problem is showing the list of recommendations for a particular person from the original person dictionary.