I'm trying to find a more detailed way to display rank for my movie website. This is my Movie.cs model
public int MovieId { get; set; }
public string MovieTitle { get; set; }
public int ViewCounter { get; set; }
I have ViewCounter which I use to count how many people visited to watch that specific Movie. This is my Controller:
public IActionResult Ranking()
{
var item = from m in databaseContext.Movies.Include("Genre").Include("Director")
where m.IsHidden == false
orderby m.ViewCounter descending
select m;
return View(item.ToList());
}
This is the View for that Controller:
@model IEnumerable<WebXemPhim.Models.Domain.Movie>
<div class="blog-list-area section pt-100 pt-lg-80 pt-md-70 pt-sm-60 pt-xs-50 pb-xs-50">
<div class="container">
<div class="row row-25">
<div class="col-lg-8">
<div class="row">
@foreach (var item in Model)
{
<div class="col-12">
<!--Single Blog Post Start-->
<div class="single-blog-post blog-list mb-30">
<div class="blog-img">
<a href="single-blog.html"><img src="~/images/@item.MovieImageName" alt=""></a>
</div>
<div class="blog-content">
<h3><a href="single-blog.html">@item.MovieTitle</a></h3>
<p>@item.MoviePlot</p>
<div class="blog-bottom">
<ul class="meta meta-border-bottom">
<li><a>@item.ViewCounter</a></li>
</ul>
</div>
</div>
</div>
<!--Single Blog Post End-->
</div>}
</div>
</div>
</div>
</div>
</div>
<!--Blog Area End-->
So far it's good, but now it's missing the RANK NUMBER ( like 1,2,3,4)(the movie with the highest views will be 1) and I just don't how to actually add an extra column with LINQ. Any suggestions? Or should I just make a new column that store RANK for each movie instead?