Hello Team,
in my order page, I'm able to save the data into the databse correctly but when i tried to pass the OrderNuMber and OrderId to the receipt view page and print the receipt after saving order I keep getting this error, any help will be appreciated.
The parameters dictionary contains a null entry for parameter 'orderId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult PrintSalesReceipts(Int32)' in 'SmartRestaurantManagement.Controllers.HomeController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
Emmmanuel FIADUFEPosted Jul 7, 2025, 7:49 AM
Hello team,
With reference to my earlier post with the issues of the OrderNumber and the OrderDate catching null reference error on the receipt view page, any additional information will highly appreciated.
Emmmanuel FIADUFEPosted Jul 4, 2025, 5:51 PM
This the OrderId value in the URL
On the Receipt View Page
@model SmartRestaurantManagement.ViewModel.OrderViewModel
Receipt #: @(Model.OrderNumber ?? "N/A")
Date/Time: @(Model.OrderDate.ToString("yyyy-MM-dd HH:mm") ?? "N/A")
Cashier: @(ViewBag.UserId ?? "Unknown")
An exception of type 'System.NullReferenceException' occurred in App_Web_4doslt4g.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
Emmmanuel FIADUFEPosted Jul 4, 2025, 4:54 PM
The array of the data always get saves perfectly into the database but the error occurs on the receipt view page, and because it is not able to pass the data to the receipt.
Emmmanuel FIADUFEPosted Jul 4, 2025, 4:50 PM
The OrderNumber is generated within the CreatePOS view page and order details are pass from the POSController to the OrderRepository to the database.
Additional help will be highly appreciated.
Emmmanuel FIADUFEPosted Jul 4, 2025, 4:43 PM
Thank you Mr Paul.
For the route, I created POSController for the order view page and the receipt view page, the HomeController maintain the default route, and also the system consist of two logins details such as the admin page for the dashboard side and POS system for the sales and printing of receipts.
I follow your steps alright but the OrderNumber, and OrderDate keep catching this NullReferenceException error and also says; Object reference not set to an instance of an object.
Tuhin PaulPosted Jul 4, 2025, 3:46 AM
The error you are encountering occurs because the
PrintSalesReceiptsaction method in yourHomeControlleris expecting a non-nullable integer (int) parameter namedorderId, but the value being passed to it isnull. Sinceintis a value type and cannot acceptnull, the framework throws this exception. YourPrintSalesReceiptsmethod likely looks like this:Here,
orderIdis a required parameter of typeint. If no value is provided fororderIdor if the value isnull, the framework cannot bind it to theintparameter.PrintSalesReceiptsaction (e.g., via a redirect or URL), theorderIdparameter is either missing or not properly passed.orderIdduring redirection after saving the order.The ASP.NET MVC framework attempts to bind route values, query strings, or form data to the action method parameters. If the binding fails (e.g.,
orderIdisnullor missing), it throws the error you are seeing.Save the Order
Print the Receipt
View (PrintSalesReceipts.cshtml):
orderIdparameter.orderIdis included.Emmmanuel FIADUFEPosted Jul 3, 2025, 3:31 PM
Hello, you guys are right, I did that modification and it look like the receipt page view is not receiving the Order number generated to print the order so due to that it giving a null error, which I'm having trouble in fixing it
Harold KelleyPosted Jul 3, 2025, 3:43 AM
It looks like the error you're facing is due to the fact that the
PrintSalesReceipts(int orderId)method requires a non-nullableint, but you’re passingnullor not passingorderIdat all when calling that action @Space WavesCk NitinPosted Jul 3, 2025, 3:37 AM
Means:
Your PrintSalesReceipts(int orderId) action expects a non-null
orderId(anintis non-nullable).But no value (or a
null) is being passed fororderIdin the URL or route data.The MVC model binder can’t assign
nullto a non-nullableint.Root causes
Here are some common reasons for this error:
The route or query string didn’t provide a value for
orderId.Example:
instead of
Solutions
Make
orderIdnullable