Issue with NullreferenceExceptions/how to manage shippingmethods in C#/Razor
I am creating a checkout page which displays a radiobuttonlist for available countries and another RBL for each shippingmethod available in the currently selected country.
The issue I am having is attempting to save an order after having set a countryId at which point I get a nullReferenceError like this:
Error Loading Razor Script (file: ) Object reference not set to an instance of an object. at TeaCommerce.Data.Order.get_ShippingMethodId() at TeaCommerce.Data.Order.Save() at ASP._Page_macroScripts_checkout_cshtml.Execute() in c:\projectdir\Checkout.cshtml:line 20
This seems to make some sense since I've not yet actually set a ShippingMethodId, but I cannot seem to figure out how to do this from the C# codebehind/Razor where this is happening, unfortunately I expect to need to set a country before I can let TeaCommerce find and manage the legal shippingmethods for that country.
Attempting to hardset a shippingmethodid instead using "order.shippingmethodid = 1", treats me to a similar error:
Error Loading Razor Script (file: ) Object reference not set to an instance of an object.
at TeaCommerce.Data.Order.get_ShippingMethodId()
at TeaCommerce.Data.Order.set_ShippingMethodId(Nullable`1 value)
which seems to suggest setting a shippingorderid is not the way to do this.
Which I guess leads me to the first question: How do I properly set a shippingmethod based on selected country from C# or Razor?
Issue with NullreferenceExceptions/how to manage shippingmethods in C#/Razor
I am creating a checkout page which displays a radiobuttonlist for available countries and another RBL for each shippingmethod available in the currently selected country.
The issue I am having is attempting to save an order after having set a countryId at which point I get a nullReferenceError like this:
Error Loading Razor Script (file: ) Object reference not set to an instance of an object. at TeaCommerce.Data.Order.get_ShippingMethodId()
at TeaCommerce.Data.Order.Save()
at ASP._Page_macroScripts_checkout_cshtml.Execute() in c:\projectdir\Checkout.cshtml:line 20
This seems to make some sense since I've not yet actually set a ShippingMethodId, but I cannot seem to figure out how to do this from the C# codebehind/Razor where this is happening, unfortunately I expect to need to set a country before I can let TeaCommerce find and manage the legal shippingmethods for that country.
Attempting to hardset a shippingmethodid instead using "order.shippingmethodid = 1", treats me to a similar error:
Error Loading Razor Script (file: ) Object reference not set to an instance of an object.
at TeaCommerce.Data.Order.get_ShippingMethodId()
at TeaCommerce.Data.Order.set_ShippingMethodId(Nullable`1 value)
which seems to suggest setting a shippingorderid is not the way to do this.
Which I guess leads me to the first question: How do I properly set a shippingmethod based on selected country from C# or Razor?
Thanks in advance
Hi Anders
Try and check the country id of the order. Is that a valid country Id and is that country in the DB?
Kind regards
Anders
That was exactely the problem, thank you :) At some point, the countryId I was reading from a member profile had been set to 0
is working on a reply...