索引.cshtml
<div class="news_content_container">
@Html.Action("_AddImagesToNews", "PostImages")
</div>
_AddImagesToNews.cshtml
<div>
@using (Html.BeginForm("_AddImagesToNews", "PostImages", FormMethod.Post, new { id = "form_post_images" }))
{
@Html.Hidden("Id", (int)ViewBag.newsId)
<div class="editor-label">
<input type="file" name="Files" id="Files" multiple="multiple" />
</div>
<div class="submit-field">
<input type="submit" value="Ekle" class="button_gray_small" />
</div>
}
</div>
<div class="images_content_container">
@Html.Partial("_PostImages", Model.ToList())
</div>
_PostImages.schtml
@model IEnumerable<NewsCMS.DAL.EDM.PostImages>
@foreach (var item in Model)
{
<img src="~/@(item.MiddleImageUrl)" alt="@(item.Posts.Title)" />
}
控制器动作
public ActionResult _AddImagesToNews(int Id)
{
using (NewsCMSEntities entity = new NewsCMSEntities())
{
ViewBag.newsId = Id;
return PartialView(entity.PostImages.Where(x => x.PostId == Id).ToList());
}
}
加载视图时,我收到错误作为标题。我找不到原因。如果我写@Model.Count()
在_PostImages.cshtml中,它会显示正确的值而没有错误。
我错过了什么?
谢谢...