这是我的观点:
@model IEnumerable<Echipament>
@{ if (Model == null)
{ <h2> No obj </h2> }
else
{
foreach (var echipament in Model)
{
<div>
<h4> Nume echipament: @echipament.Name</h4>
<p> Pret: @echipament.Price.ToString("c")</p>
</div>
}
}
}
这是我的控制者:
public class EchipamentController : Controller {
private ICategoryRepository categoryRepository;
private IEchipamentRepository echipamentRepository;
public EchipamentController() {
_categoryRepository = categoryRepository;
_echipamentRepository = echipamentRepository;
}
public ViewResult List() {
var echipamente = _echipamentRepository.Echipamente;
return View(echipamente);
}
}
我不明白为什么会出现此错误,因为到目前为止,我已经使用过类似的示例,但没有遇到这个问题。任何帮助,解释都很好。提前致谢! 看来我的模型为空。.