We have already created first page which will show all the news articles. This page will show Complete article.
Add One more Action Method to HomeController
[SharePointContextFilter]
public ActionResult Aticle(int ArticleId)
{
User spUser = null;
var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);
FullArticle article = new FullArticle();
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
if (clientContext != null)
{
spUser = clientContext.Web.CurrentUser;
clientContext.Load(spUser, user => user.Title);
clientContext.ExecuteQuery();
ViewBag.UserName = spUser.Title;
List lst = clientContext.Web.Lists.GetByTitle("News");
CamlQuery queryNews = new CamlQuery();
queryNews.ViewXml = @"<View><Query><Where><Eq><FieldRef Name='ID'/>" + "<Value Type='Number'>" + ArticleId + "</Value></Eq></Where></Query>" +
"<ViewFields><FieldRef Name='ID'/><FieldRef Name='Title'/><FieldRef Name='Body'/></ViewFields></View>";//
ListItemCollection newsItems = lst.GetItems(queryNews);
clientContext.Load(newsItems, includes => includes.Include(i => i.Id, i => i.DisplayName, i => i["Body"]));
clientContext.ExecuteQuery();
if (newsItems != null)
{
foreach (var lstProductItem in newsItems)
{
article.Id = Convert.ToInt32(lstProductItem.Id.ToString());
article.Title = lstProductItem.DisplayName.ToString();
article.Body = lstProductItem["Body"].ToString();
}
}
}
}
return View(article);
}
Again Right click on Action and create a View with same name Action method name. In My case View will be called Aticle
@model SharePointNewsAppWeb.Models.FullArticle
@{
ViewBag.Title = "Aticle";
}
<br />
<div class="panel panel-default">
<div class="panel-heading"><a style="font-size:20px;" href="/"><i class="glyphicon glyphicon-chevron-left"></i> <i class="glyphicon glyphicon-home"></i> </a></div>
<div class="panel-heading"><h1 class="h2">@Model.Title.ToUpper()</h1></div>
<div class="panel-body">@Html.Raw(@Model.Body)</div>
</div>
This is the code for Full article page which shows Body of the news article