Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anders Grahn 14 posts 94 karma points
    Feb 01, 2013 @ 10:47
    Anders Grahn
    0

    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

  • Anders Burla Johansen 2560 posts 8256 karma points
    Feb 04, 2013 @ 11:13
    Anders Burla Johansen
    100

    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

  • Anders Grahn 14 posts 94 karma points
    Feb 06, 2013 @ 11:40
    Anders Grahn
    0

    That was exactely the problem, thank you :) At some point, the countryId I was reading from a member profile had been set to 0

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies