system.nullreferenceexception对象引用未设置为对象mvc asp.net视图的实例

时间:2018-03-28 13:22:52

标签: asp.net-web-api asp.net-mvc-5

Hi Guys.My problem is that i won't be able to display data that is coming from my controller to my view. i got this error.Someone can help me please !

    @model GRHModel.ListeDemandeConger
   @{
   ViewBag.Title = "AfficherMesDemandes";
   Layout = "~/Views/Home/Common.cshtml";
   }

   <table class="table table-responsive" style="width:400px">
   @foreach (var dc in  Model.ldc)
   {

    <tr>
        <td>
            @Html.DisplayFor(i =>dc.DateDebut)
        </td>
    </tr>

   }

   </table>

1 个答案:

答案 0 :(得分:0)

您的模型为空。 用IF检查模型!= null。

围绕你的foreach
@if (Model != null)
{
   your foreach
}