yüzden özellikle yazılan bir görünüm oluşturma örneğine ayarlanmadı. Benim modelim RestaurantReview.cs aradı ve görünümü de şu:kesinlikle yazılı .net görünüm Modeli nesne
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace OdeToFood.Models
{
public class RestaurantReview
{
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
public string Country { get; set; }
public int Rating { get; set; }
}
}
Ben Visual Studio benziyor bu dayanan özellikle yazılan Liste modeli oluşturmak etmişti:
@model IEnumerable<OdeToFood.Models.RestaurantReview>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.City)
</th>
<th>
@Html.DisplayNameFor(model => model.Country)
</th>
<th>
@Html.DisplayNameFor(model => model.Rating)
</th>
<th></th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.City)
</td>
<td>
@Html.DisplayFor(modelItem => item.Country)
</td>
<td>
@Html.DisplayFor(modelItem => item.Rating)
</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>
Ben çalıştırdığınızda Site, ben Modeli nesnesini vurgulama ve belirten "@foreach (Modeli var item)" satırında bir boş gösterici istisna olsun "nesne başvurusu bir nesnenin örneğine ayarlanmadı."
gerçekten ben bile yazmadım çünkü bu kodu yanlış olabilir nasıl anlamak değil, Visual Studio yaptı. Burada ne oluyor? Eğer Controller
içinde doğru bir model örneği değil gibi
Bu görünümü dönen kontrolör Eylem kodunu gösterebilir
null
istisna almazsınız? Modeliniz orada örneklendirilmelidir. –nasıl 'Controller' benziyor geliyor? Herhangi bir 'IEnumrable' '' '' '' '' Denetleyicinizden mi geçersiniz? –
Ian