1

I am using the following codes..

Controller:

 public ActionResult Comments(int? Id)
    {
        var abccomment= db.xyzComments.Include(c=>c.XYZMasters);
     var comments = (from x in abccomment
                        where Id == x.CcId
                        select x.Comment).Distinct().ToList();

        return View(comments);
    } 

and my view is

@model IEnumerable<Pharman.Models.XYZMaster>
@foreach (var item in Model)
    {

        @item.XYZComment.Comment
    }

I get the following error: The model item passed into the dictionary is of type 'System.Collections.Generic.List1[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[farma.Models.XYZMaster].

pls help... TIA

Anjali
  • 73
  • 3
  • 4
  • 13
  • this is similar to this post:- http://stackoverflow.com/questions/4813307/the-model-item-passed-into-the-dictionary-is-of-type-but-this-dictionary-req – sankoobaba Feb 11 '14 at 06:33

1 Answers1

7

Type of your ViewModel is IEnumerable<Pharman.Models.XYZMaster> but you are passing List<string>

You should change your ViewModel type to IEnumerable<string>

Then:

@model IEnumerable<string>
@foreach (var comment in Model)
{

    @comment
}
Selman Genç
  • 100,147
  • 13
  • 119
  • 184