私は自分のコントローラーに持っていますが、それが正しいかどうかわかりません
[HttpGet]
[NoCache]
public ActionResult ListCommentsOnNews(int newsId, string newsComment) ???
{
//code here with return
}
私の Article.aspx ビューで:
<div class="news-comment-content" id="news-comment-content">
<% if (Model.Results != null)
{ %>
<% foreach (var newsItem in Model.Results.NewsComments)
{ %>
<% Html.RenderPartial("SetCommentOnNews", newsItem); %>
<%} } %>
</div>
次に、部分的な ListCommentsOnNews.ascx:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<???>" %>
<div class="news-post-list-item">
<div class="news-post-user-info-wrapper">
<div class="avatar">
<img width="52" height="52" alt="Avatar" src="/ThemeFiles/Base/images/User/user-avatar.png" />
</div>
<div class="who-and-when-box">
<%: newsItem.CommentDate %> //get error here
<br />
<br />
<%: ViewBag.UserName %>
</div>
<div class="news-comment"><%: newsItem.NewsComment %></div> //and get error here
<div class="clear"></div>
</div>
<div class="clear"></div>
</div>
私のコントローラー:
[HttpGet]
public ActionResult Article(int id, int? page)
{
var news = ZincService.NewsService.GetNewsForId(id);
var allNewsComments = ZincService.NewsService.GetAllNewsCommentsForId(id, page.GetValueOrDefault(1), 10);
var currentUser = ZincService.GetUserForId(CurrentUser.UserId);
if (news == null || news.PublishingState != PublishingState.Live)
return RedirectToAction("NotFound");
if (allNewsComments != null)
{
var user = ZincService.GetUserForId(currentUser.UserId);
if (user == null || user.Customer.CustomerId != CurrentCustomer.CustomerId)
return DataNotFound();
ViewBag.Avatar = user.UserImage;
ViewBag.UserName = user.Firstname + " " + user.Surname;
NewsCommentsViewModel model = (NewsCommentsViewModel)SetNewsArticleViewModel(news, new NewsCommentsViewModel());
foreach (var newsItem in allNewsComments.NewsComments)
{
model.Results = allNewsComments;
model.PageSize = 10;
model.CurrentPage = page.GetValueOrDefault(1);
}
return View(model);
}
else
{
return View(SetNewsArticleViewModel(news,null));
}
}
[NonAction]
private NewsArticleViewModel SetNewsArticleViewModel(Entities.News.News news, NewsArticleViewModel viewModel)
{
viewModel.News = news;
viewModel.IsFavourite = ZincService.FavouriteService.IsFavouriteForUser(CurrentUser.UserId, news);
viewModel.DownloadAttachments = news.NewsAttachments.Where(x =>
Core.FileFormat.FileFormatHelper.GetFileFormatType(x.FileExtension) == Core.FileFormat.FileFormatType.Excel ||
Core.FileFormat.FileFormatHelper.GetFileFormatType(x.FileExtension) == Core.FileFormat.FileFormatType.PDF ||
Core.FileFormat.FileFormatHelper.GetFileFormatType(x.FileExtension) == Core.FileFormat.FileFormatType.PowerPoint ||
Core.FileFormat.FileFormatHelper.GetFileFormatType(x.FileExtension) == Core.FileFormat.FileFormatType.Word);
viewModel.EmbedAttachments = news.NewsAttachments.Where(x =>
Core.FileFormat.FileFormatHelper.GetFileFormatType(x.FileExtension) == Core.FileFormat.FileFormatType.Video);
return viewModel;
}
現在のコンテキストに存在しないことを示す newsItem パーツでエラーが発生します。誰かが私を助けてくれませんか?