2017-05-11 5 views
1

私の見解で私の顧客のリストを表示しようとしています。は、 'System.Collections.Generic.List`型ですが、この辞書には' System.Collections.Generic.IEnumerable`が必要です

辞書に渡されたモデルアイテムのタイプがある「モデル層に私のリストを記入してあるpdf.view_model.View_modelを投げ渡しでSystem.Collections.Generic.List 1[PDF.View_model.Customers]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable

public IEnumerable<Customers> GetAllCustomers(int? _id) 
    { 
     Ref_customers = new List<Customers>(); 
     CList = new List<Models.EF_Model.Customer>(); 
     foreach (var item in CList) 
     { 
      Ref_customers.Add(new Customers() { id = item.Id, FName = item.FName, LName = item.LName, Paid = item.Paid }); 
     } 
     return Ref_customers; 

と私のコントローラの私のモデルで

` public List<EF_Model.Customer> GetAllCustmers(int? _id) 
     { 
      using (var Context = new EF_Model.CoolerEntities()) 
      { 
       return (_id.HasValue ? Context.Customers.Where(p => p.Id == _id).ToList() : Context.Customers.ToList()); 
      } 
     }` 

し、最終的に

`

 public ActionResult Index(int? id) 
     { 
      Ref_ViewModel = new View_model.View_Model(); 
      return View(Ref_ViewModel.GetAllCustomers(id)); 
     } 
` 

と私の見解では私はそれがで顧客のリストを表示し、それを少量投稿foreach文の末尾

` 
@model IEnumerable<PDF.View_model.Customers> 

@{ 
    ViewBag.Title = "Index"; 
} 

<h2>Index</h2> 

<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
<table class="table"> 
    <tr> 
     <th> 
      @Html.DisplayNameFor(model => model.FName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.LName) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.Paid) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.Password) 
     </th> 
     <th> 
      @Html.DisplayNameFor(model => model.Email) 
     </th> 
     <th></th> 
    </tr> 

@foreach (var item in Model) { 
    <tr> 
     <td> 
      @Html.DisplayFor(modelItem => item.FName) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.LName) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Paid) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Password) 
     </td> 
     <td> 
      @Html.DisplayFor(modelItem => item.Email) 
     </td> 
     <td> 
      @Html.ActionLink("Edit", "Edit", new { id=item.Id }) | 
      @Html.ActionLink("Details", "Details", new { id=item.Id }) | 
      @Html.ActionLink("Delete", "Delete", new { id=item.Id }) 
     </td> 
    </tr> 
} 

</table> 

model.custom erは単に私のテーブルのDTO私はまた、私はリストがIEnumrableがちょうど

私は何をすべきかを知らないことを知っている?

がどのように私はIEnumerableをにリストを変換することができ、私のview_model.Customerの1を持っています混乱した

+0

タイプ 'System.Collections.Generic.IEnumerableタイプの_...が見つかりません。 _ –

+0

@StephenMuecke IEnumerable 1 [PDF.Models.EF_Model.Customer]'。 –

+0

2つの得意先クラス、PDF.View_model.CustomersおよびPDF.Models.EF_Model.Customerがありますか? – sachin

答えて

1

あなたは2つの顧客クラスを持っているようです。コントローラーから1つのタイプを渡し、もう1つのタイプをビューでModelとして使用しています。

はどちらか、あなたは他のタイプPDF.View_model.Customersを使用し、またはType PDF.Models.EF_Model.Customer

1

確かにあなたのリストですIEnumerable<PDF.View_model.Customers>のコントローラパスViewModelを作るためにあなたのビューを更新する必要がありますが、何が必要IEnumerable<PDF.Models.EF_Model.Customer>です。

これは一致しないListではありません。その一般的なパラメータです。

関連する問題