こんにちは、コントローラーに次のコードがあります。
public ViewResult Index(string Ordering, int? CounterForPage)
{
var FullDatabaseItem = from b in db.tblGames
select b;
{
var Info = db.tblGames.Include(x => x.tblConsole).Where(UserInfo => UserInfo.UserName.Equals(User.Identity.Name)).ToList();
return View(Info);
}
switch (Ordering)
{
case "HeadlineName":
FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.GameName);
break;
case "DatePosted":
FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.ReleaseYear);
break;
case "DiscriptionDate":
FullDatabaseItem = FullDatabaseItem.OrderBy(b => b.ReleaseYear);
break;
default:
FullDatabaseItem = FullDatabaseItem.OrderByDescending(b => b.ReleaseYear);
break;
}
int pageSize = 3;
int pageNumber = (CounterForPage ?? 1);
var PageNumberResults = FullDatabaseItem.ToPagedList(pageNumber, pageSize);
ViewBag.PageNumberResults = FullDatabaseItem.Count();
if (PageNumberResults.Any())
{
return View(PageNumberResults);
}
return View("ErrorView");
}
次のコードを削除すると、ページングが機能します。
`var Info = db.tblGames.Include(x => x.tblConsole).Where(UserInfo => UserInfo.UserName.Equals(User.Identity.Name)).ToList();`
return View(Info);
しかし、下に緑色の下線があり、次のように書かれてswitch (ordering)
います。
Unreachable Code Dectected
アプリケーションの一部であるため、両方が必要です。あなたの親切な努力に感謝します。
私のビュー コード:
@model PagedList.IPagedList<Games.Models.tblGame>
@{
ViewBag.Title = "Index";
}
@*<h2>Index</h2>*@
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
@* <tr>*@
@* <th>
GameID
</th>*@
@* <th>
GameName
</th>
<th>
ReleaseYear
</th>
<th>
Cost
</th>
<th>
Description
</th>
<th>
Downloads
</th>
<th>
Image
</th>
<th>
tblConsole
</th>*@
@* <th>
UserName
</th>*@
@* <th></th>
</tr>*@
@foreach (var item in Model) {
<tr>
@* <td>
@Html.HiddenFor(modelItem => item.GameID)
</td>*@
<td id = "TableLayout1">
<img width="100" height="100"alt="ImageFromDatabase" src='@item.Image' />
</td>
<td id = "TableLayout2">
@*@Html.DisplayFor(modelItem => item.GameName)*@
@Html.ActionLink(item.GameName, "Details", new { id = item.GameID })
</td>
<td id = "TableLayout3">
@Html.DisplayFor(modelItem => item.ReleaseYear)
</td>
<td id = "TableLayout4">
@Html.Raw(item.Description.Substring(0, item.Description.IndexOf(".") + 1))
@* @Html.DisplayFor(modelItem => item.Description)*@
</td>
<td id = "TableLayout5">
@Html.DisplayFor(modelItem => item.Cost)
</td>
<td id = "TableLayout6">
@Html.DisplayFor(modelItem => item.Downloads) @*want this as a link so I can then click on it and show the game downloads*@
</td>
<td id = "TableLayout7">
@Html.DisplayFor(modelItem => item.tblConsole.ConsoleName)
</td>
@* <td>
@Html.HiddenFor(modelItem => item.UserName)
</td>*@
<td id = "TableLayout8">
@Html.ActionLink("Edit", "Edit", new { id=item.GameID }) |
@Html.ActionLink("Details", "Details", new { id = item.GameID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.GameID })
</td>
</tr>
}
</table>
<div class="PageCounter">
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber)
of @Model.PageCount
@if (Model.HasPreviousPage)
{
@Html.ActionLink("<<", "Index", new { CounterForPage = 1, Ordering = ViewBag.CurrentSort, WordFilter = ViewBag.WordFilter })
@Html.Raw(" ");
@Html.ActionLink("< Previous Page", "Index", new { CounterForPage = Model.PageNumber - 1, Ordering = ViewBag.CurrentSort, WordFilter = ViewBag.WordFilter })
}
else
{
@:<<
@Html.Raw(" ");
@:< Prev
}
@if (Model.HasNextPage)
{
@Html.ActionLink("Next Page >", "Index", new { CounterForPage = Model.PageNumber + 1, Ordering = ViewBag.CurrentSort, WordFilter = ViewBag.CurrentFilter })
@Html.Raw(" ");
@Html.ActionLink(">>", "Index", new { CounterForPage = Model.PageCount, Ordering = ViewBag.CurrentSort, WordFilter = ViewBag.CurrentFilter })
}
else
{
@:Next>
@Html.Raw(" ")
@:>>
}
</div>
<script type="text/javascript">
var uvOptions = {};
(function () {
var uv = document.createElement('script'); uv.type = 'text/javascript'; uv.async = true;
uv.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'widget.uservoice.com/ZRhsC1RL1m4gK5megTxxlw.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(uv, s);
})();
</script>
作成されたクラス:
namespace Games.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web;
using PagedList;
using System.Web.Mvc;
public class MyViewModel
{
public MyInfo Info { get; set; }
public PageNumberResults { get; set; }
}
}
クラスからのエラー:
Error 1 Invalid token '{' in class, struct, or interface member declaration
Error 2 Invalid token ';' in class, struct, or interface member declaration
Error 3 Invalid token ';' in class, struct, or interface member declaration
Error 4 Type or namespace definition, or end-of-file expected