2016-06-19 2 views
-1

アプリケーションを実行した後、私はモデル項目は型であるが、この辞書はタイプのモデルアイテムを要求「System.Collections.Generic.IEnumerable`1 []」

The model item passed into the dictionary is of type 'MvcWcfApplication.ServiceReference1.StudentDetail[]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[MvcWcfApplication.ServiceReference1.ServiceClient].

を得ますビューで

@model IEnumerable<MvcWcfApplication.ServiceReference1.ServiceClient> 
.... 
<table> 
    <tr> 
     <th></th> 
    </tr> 
    @foreach (var item in Model) 
    { 
     <tr> 
      <td> 
       @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | 
       @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | 
       @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) 
      </td> 
     </tr> 
    } 
</table> 

DbController.cs

public class DbController : Controller 
{ 
    public ActionResult Index() 
    { 
     ServiceReference1.ServiceClient obj = new ServiceReference1.ServiceClient(); 
     return View(obj.GetStudents()); 
    } 
} 

マイiService.cs

// NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService" in both code and config file together. 
[ServiceContract] 
public interface IService 
{ 
    [OperationContract] 
    List<StudentDetail> GetStudents(); 
+1

エラーメッセージは自明です。 'List 'を返すサービスを呼び出して、 'IEnumerable ' - 'StudentDetail'が** ServiceClientでないことを期待するビューに渡します。 –

+0

'IEnumerable IEnumerableを 『 – llouk

+0

新しいエラー コンパイラエラーメッセージ:CS0426:型の名前『」 に』StudentDetail』のタイプには存在しません 『MvcWcfApplication.ServiceReference1.ServiceClient』 – Ollivander

答えて

0

次の変更を試してください。

public ActionResult Index() 
    { 
    ServiceReference1.ServiceClient obj = new ServiceReference1.ServiceClient(); 
    return View(obj.GetStudents().ToList()); 
    } 

ビューを次のように変更します。あなたのStudentDetailクラスで "item.StudentName" のような 何かを生徒のプロパティの値を印刷する必要がある

@model IEnumerable<MvcWcfApplication.ServiceReference1.ServiceClient.StudentDetail> 

編集

@model IEnumerable<MvcWcfApplication.ServiceReference1.StudentDetail> 

表示学生

。 StudentNameはクラス内のプロパティです。

<table> 
    <tr> 
     <th></th> 
    </tr> 
    @foreach (var item in Model) 
    { 
     <tr> 
      <td> item.StudentName </td> 
      <td> 
       @Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) | 
       @Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) | 
       @Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ }) 
      </td> 
     </tr> 
    } 
</table> 
+0

私はそれを試してみましたが、それはしていません私の "StudentDetail"を認識してください。私に不思議な線を与えます。 – Ollivander

+0

@Ollivanderビューを閉じて再度開いてみてください。 Intellisenseは、名前空間をインポートするときに常に機能しません。コンパイルして実行する必要があります。 –

+0

新しいエラー:コンパイラエラーメッセージ:CS0426:タイプ 'StudentDetail'がタイプ 'MvcWcfApplication.ServiceReference1.ServiceClient'に存在しません – Ollivander

関連する問題