我有以下看法:
@model IEnumerable<YIS2.Models.Testimonial>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div id="Testimonials">
<h2>Our Testimonials</h2>
@foreach (var item in Model)
{
<blockquote>
<p>@item.Content</p>
<p>@item.AuthorName</p>
</blockquote>
}
</div>
<div id="SubmitTestimonial">
<h2>Submit Testimonial</h2>
@using (Html.BeginForm("NewTestimonial", "Testimonial", FormMethod.Post))
{
@Html.EditorFor(m => Model.AuthorName)
@Html.EditorFor(m => Model.AuthorEmail)
@Html.EditorFor(m => Model.Content)
<input type="submit" id="submitTestimonial" />
}
我需要模型是 IEnumerable 的,这样我就可以遍历内容以显示以前保存的推荐信。问题是我在语句 m => Model.x 上遇到错误,因为 Model 是 IEnumerable。
请问最好的解决方法是什么?