Hi Everybody i have a problem in code related to print Purchases's Report between to Period .
But this Error is Shown to Me
An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Reports_reportPurchaseDate.<executeasync>b__13_0() in reportPurchaseDate.cshtml, line 73
Stack Query Cookies Headers Routing
NullReferenceException: Object reference not set to an instance of an object.
AspNetCore.Views_Reports_reportPurchaseDate.<executeasync>b__13_0() in reportPurchaseDate.cshtml
+
line 73 @item.products.ProductName
What I have tried:
my Controller
public IActionResult reportPurchaseDate( DateTime datefrom, DateTime dateto)
{
bool isrole = getRole();
if (isrole == true)
{
var rpt = _Context.orderDetails.Where(c => c.masterID.Order_Kind_ID == 1 && c.masterID.DateAdded >= datefrom && c.masterID.DateAdded <= dateto)
.Include(c => c.masterID)
.Include(c => c.products.ProductName)
.Include(c => c.products.quantity)
.Include(c => c.products.price);
return View(rpt);
}
else
{
return RedirectToAction("noaccess", "HomeController");
}
}
my View
@model IEnumerable<orderdetails>
@{
ViewData["Title"] = "report purchase Date";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>تقرير مشتريات فترة</h1>
<table class="table"><tbody><tr> <td> @Html.TextBox("datefrom")
</td> <td> تاريخ بداية
</td> </tr> <tr> <td> @Html.TextBox("dateto")
</td> <td> تاريخ نهاية
</td> </tr> <tr> <td>
</td> <td> </td> </tr> </tbody></table>
<hr>
<hr>
<div class="row" id="divprint">
<div class="col-md-12">
<div class="content-panel">
<h4>
تقرير المشتريات خلال فترة
</h4>
<hr>
@foreach (var item in Model)
{
}
<table class="table"><thead> <tr> <td> المنتج
</td> <td> السعر
</td> <td> الكمية
</td> <td> تاريخ الفاتورة
</td> </tr> </thead> <tbody><tr> <td> @item.products.ProductName
</td> <td> @item.Product_Price
</td> <td> @item.Product_Quantity
</td> <td> @item.masterID.DateAdded.ToShortDateString()
</td> </tr></tbody> </table>
</div>
</div>
</div>
@section Scripts{
function PrintElem(elem) {
Popup($(elem).html());
}
function Popup(data) {
var myWindow = window.open('', 'my div', 'height=500,width=600');
myWindow.document.write('<html><head><title>my div</title>');
myWindow.document.write('<link rel="stylesheet" href="/lib/bootstrap/css/bootstrap.min.css" type="text/css" />');
myWindow.document.write('</head><body >');
myWindow.document.write(data);
myWindow.document.write('</body></html>');
myWindow.document.close(); // necessary for IE >= 10
myWindow.onload = function () { // necessary if the div contain images
myWindow.focus(); // necessary for IE >= 10
myWindow.print();
myWindow.close();
};
}
}