count news

This commit is contained in:
2024-08-01 17:28:00 +03:30
parent d73b5dc266
commit fbb2d406cb
4 changed files with 61 additions and 6 deletions

View File

@ -13,6 +13,8 @@ namespace WebApplication1.Controllers
public ActionResult Index() public ActionResult Index()
{ {
ViewBag.newsCount = db.news.Count();
ViewBag.views = "";
setTitle(); setTitle();
return View(); return View();
} }

View File

@ -10,14 +10,14 @@
</section> </section>
<div class="row"> <div class="row">
<section class="col-md-4" aria-labelledby="gettingStartedTitle"> <section class="col-md-4" aria-labelledby="newsTitleDisplay">
<h2 id="gettingStartedTitle">Getting started</h2> <h2 id="newsTitleDisplay">News count</h2>
<p> <p>
ASP.NET MVC gives you a powerful, patterns-based way to build dynamic websites that @ViewBag.newsCount
enables a clean separation of concerns and gives you full control over markup </p>
for enjoyable, agile development. <p>
<a class="btn btn-outline-dark" href="/news"> Start Reading &raquo;</a>
</p> </p>
<p><a class="btn btn-outline-dark" href="https://go.microsoft.com/fwlink/?LinkId=301865">Learn more &raquo;</a></p>
</section> </section>
<section class="col-md-4" aria-labelledby="librariesTitle"> <section class="col-md-4" aria-labelledby="librariesTitle">
<h2 id="librariesTitle">Get more libraries</h2> <h2 id="librariesTitle">Get more libraries</h2>

52
Views/news/Latest.cshtml Normal file
View File

@ -0,0 +1,52 @@
@model IEnumerable<WebApplication1.Models.news>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.title)
</th>
<th>
category
</th>
<th>
@Html.DisplayNameFor(model => model.tag)
</th>
<th>
@Html.DisplayNameFor(model => model.publishDate)
</th>
<th>
@Html.DisplayNameFor(model => model.views)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.title)
</td>
<td>
@Html.DisplayFor(modelItem => item.cat)
</td>
<td>
@Html.DisplayFor(modelItem => item.tag)
</td>
<td>
@Html.DisplayFor(modelItem => item.publishDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.views)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.ID }) |
@Html.ActionLink("Details", "Details", new { id = item.ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.ID })
</td>
</tr>
}
</table>

View File

@ -275,6 +275,7 @@
<Content Include="Views\tags\Details.cshtml" /> <Content Include="Views\tags\Details.cshtml" />
<Content Include="Views\tags\Edit.cshtml" /> <Content Include="Views\tags\Edit.cshtml" />
<Content Include="Views\tags\Index.cshtml" /> <Content Include="Views\tags\Index.cshtml" />
<Content Include="Views\news\Latest.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="App_Data\" /> <Folder Include="App_Data\" />