0

i have in my controller and im not sure if i have it correct

[HttpGet]
[NoCache]
public ActionResult ListCommentsOnNews(int newsId, string newsComment) ???
{
  //code here with return
}

in my Article.aspx view:

<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>

then my partial 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>   

my controller:

   [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;
}

i get errors on the newsItem parts stating that it does not exist in the current context. can some one help me right please?

1 Answer 1

2

As i inferred from code you posted, problem is with you'r usage of Model.you are trying to use model properties,but you are not doing it correctly.try following :

<%
      Model.CommentDate
     %>

instead of

<%: newsItem.CommentDate %>  //get error here
Sign up to request clarification or add additional context in comments.

4 Comments

Model. with intellisense gives me nothing though I want to know what to put in my controller parameter list and also in Inherits="System.Web.Mvc.ViewUserControl<???> please, thanks
what is return type of SetNewsArticleViewModel(news,null)?
thanks i still get that error though, am i calling my partial correctly in the Article view? What must I pass in? <% Html.RenderPartial("SetCommentOnNews", newsItem); %> is this correct?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.