2014-02-11 2 views
1

Я использую следующие коды ..модель элемент передается в словарь типа «System.Collections.Generic.List`1 [System.String]», но требует типа «что-то еще»

контроллера:

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); 
    } 

и мой взгляд

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

     @item.XYZComment.Comment 
    } 

Я получаю следующее сообщение об ошибке: модели элемент передается в словарь типа «System.Collections.Generic.List 1[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable 1 [farma.Models.XYZMaster].

Просьба помочь ... ТИА

+0

этой аналогичен этому сообщению: - http://stackoverflow.com/questions/4813307/the-model-item-passed-into-the-dictionary-is-of-type-but-this-dictionary-req – sankoobaba

ответ

7

Тип вашего ViewModel является IEnumerable<Pharman.Models.XYZMaster>, но вы передаете List<string>

Вы должны изменить свой ViewModel тип в IEnumerable<string>

Тогда:

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

    @comment 
} 
+0

Спасибо Selman22 – ARC

Смежные вопросы

 Смежные вопросы