In MVC5 I added NuGet PagedList.Mvc and placed using PagedList; above.
I am having problems with two things:
first, I am getting the NullException from line;
return View(edit.thistable.ToPagedList(pageNumber, pageSize));
second, not able to see if the paging is working.
Error code:
An exception of type 'System.ArgumentNullException' occurred in System.Core.dll but was not handled in user code
HomeController.cs
public class HomeController : Controller
{
private testContext db = new testContext();
private EditModel edit = new EditModel();
public ActionResult Index(int? page)
{
try
{
edit.thistable = db.Data1.ToList();
}
catch (Exception ex)
{
edit.errorcode = ex.ToString();
}
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(edit.thistable.ToPagedList(pageNumber, pageSize));
}
Index.cshtml
@model List<EditTables.Models.Table1>
<center><table>
@foreach (var item in Model) {
<tr>
<td>
@Html.TextBoxFor(modelItem => item.Idt)
</td>
<td>
@Html.TextBoxFor(modelItem => item.datetime0)
</td>
<td>
@Html.TextBoxFor(modelItem => item.col1)
</td>
<td>
@Html.TextBoxFor(modelItem => item.col2)
</td>
<td>
@Html.TextBoxFor(modelItem => item.col3)
</td>
</tr>
}
</table></center>
Class1.cs
public class Table1
{
[Key]
public int Idt { get; set; }
public string datetime0 { get; set; }
public string col1 { get; set; }
public string col2 { get; set; }
public string col3 { get; set; }
}
public class EditModel
{
public string errorcode { get; set; }
public List<Table1> thistable { get; set; }
}
public class testContext : DbContext
{
public DbSet<Table1> Data1 { get; set; }
}