开发者

help with basic MVC project

开发者 https://www.devze.com 2022-12-29 00:12 出处:网络
i am creating a demo MVC project and i am getting a Null Object Reference error for the following code.

i am creating a demo MVC project and i am getting a Null Object Reference error for the following code.

<% 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>
       <td>
           <%= Html.Encode(item.ContactEmail) %>
       <开发者_JS百科;/td>
       <td>
           <%= Html.Encode(item.YourQuery) %>
       </td>
   </tr>
<% } %>

i get an error in the first line itself (var item in Model) coz i am getting the Model object as null.

Can anyone please help me.

thanks.


You should pass a model in your controller action:

public ActionResult Index()
{
    return View(new YourModel());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消