Asp.Net KeyValuePair <string,{=“”} =“”>不包含定义或扩展名

时间:2016-09-10 11:47:19

标签: c# asp.net asp.net-mvc

我创建了一个网络应用程序,您可以在其中为一个人提供推荐,一个人可以有多个推荐,并且我想要查看特定人员的所有推荐。一旦我点击链接查看建议,我就会收到错误消息:

  

&#39; KeyValuePair&lt;`string,Recommendation&gt;不包含&#39;建议&#39;的定义并没有推广方法&#39;建议&#39;接受类型&#39; KeyValuePair&#39;的第一个参数。可以找到。

这是我的一些代码,希望有人可以帮我解决这个问题,我已经坚持了几个小时。

推荐控制器

&#13;
&#13;
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]);    
        }
    }
}
&#13;
&#13;
&#13; 人与人推荐模型

&#13;
&#13;
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; }
    }
&#13;
&#13;
&#13;

显示视图

&#13;
&#13;
@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>
&#13;
&#13;
&#13;

拜托,任何帮助都会很棒。

修改 但是,对字典进行迭代并不是我的问题,我已经遍历了我的人字典,以显示我已添加到列表中的所有人。我的问题是显示原始人字典中特定人的推荐列表。

0 个答案:

没有答案
相关问题